users@glassfish.java.net

Re: Accessing JNDI resources from webapp

From: Major Péter <majorpetya_at_sch.bme.hu>
Date: Mon, 19 Apr 2010 16:46:51 +0200

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