users@glassfish.java.net

Re: Accessing JNDI resources from webapp

From: Jagadish Prasath Ramu <Jagadish.Ramu_at_Sun.COM>
Date: Mon, 19 Apr 2010 22:52:53 +0530

Yes, you can access the resources using JNDI name, but that is non
portable.
AFAIK, the library will be accessed in the context of a component (eg:
the library is used by web/ejb component), it gets access to the
environment (eg: resource-ref) of the calling component (ejb/web) and
the hence portable way of lookup ( eg: "java:comp/env/RESOURCE") will
also work fine.

Thanks,
-Jagadish

On Mon, 2010-04-19 at 18:28 +0200, Major Péter wrote:
> Clearing up the problem:
> If I can access a resource with JNDI name from a library, then why can't
> I use the same JNDI name from my webmodule/enterprise app?
> Thanks
>
> Regards,
> Peter
>
> 2010-04-19 16:46 keltezéssel, Major Péter írta:
> > My problem is with this, is when for example you add an EJB module to an
> > EAR project. When you do so, you need to add an <ejb-ref> entry in your
> > web.xml with a mapped name, but if you write a library, which uses the
> > JNDI name (so not the mapped name), then the library can access the
> > resource, and you don't need to add the ejb-ref to the web.xml that way.
> > But a simple webmodule can't access the EJB module by reffering to the
> > JNDI-name (without <ejb-ref> entry).
> >
> > Regards,
> > Peter
> >
> > 2010-04-19 16:18 keltezéssel, Jagadish Prasath Ramu írta:
> >> You can refer :
> >> http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Resources2.html#64057
> >>
> >> "The JNDI name of a resource and the name of the resource reference are
> >> not the same. This approach to naming requires that you map the two
> >> names before deployment, but it also decouples components from
> >> resources. Because of this decoupling, if at a later time the component
> >> needs to access a different resource, you don't have to change the name
> >> in the code. This flexibility also makes it easier for you to assemble
> >> J2EE applications from preexisting components."
> >>
> >> Thanks,
> >> -Jagadish
> >>
> >> On Mon, 2010-04-19 at 15:27 +0200, Major Péter wrote:
> >>> Hi,
> >>>
> >>> Why is that, that if I want to access a JNDI resource from a
> >>> web/enterprise app, then I have to add to the web.xml a resource-ref? Is
> >>> this really necessary?
> >>> If I create a simple JAR library, which access to this JNDI resource,
> >>> and add to the webmodule as a simple dependency (so it's not a module),
> >>> then the library can access the resource without web.xml magic, probably
> >>> because it's loaded by a different classloader then the main project is.
> >>> So why does the resource-management works like this?
> >>> I'm just asking..
> >>>
> >>> Regards,
> >>> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>