This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes basic JNDI question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "basic JNDI question." Watch "basic JNDI question." New topic
Author

basic JNDI question.

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 314
in an initial context I have seen both

ic.lookup("java:comp/env/ejb/MyEJB")
and
ic.lookup("ejb/MyEJB");

When I have played with this on previous applicatons. It works properly.


I am curious why the "java:comp/env"? What does this let me do


CIAO Peter M. Cooke
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
the "java:comp/env" part comes into play for certain J2EE components that have their own naming environment. It allows the code to refer to a JNDI object, but have the actual object looked up to be defined declaratively (via the web or EJB deployment descriptor files).

For example, an out-of-the-box J2EE component would need to use the "java:comp/env" stuff since source code isn't distributed along with the purchase. There are other reasons of course. The EJB spec recommends that all JNDI lookups have ejb-refs, or local-ejb-refs as the case may be.

If the client isn't an EJB client, using java:comp/env doesn't make any sense, as far as I know, unless you have some sort of custom context factory doing some cool stuff for you.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 314
I do wish my comany would use ejb's more.
What I hear you saing, combined with some sun class knowledge.

Depending on the appserver: the various containers (application, web, ejb,...) could have thier very own jndi context.

a Servlet probably could lookup(java:comp/env/ejb/MyEBJ) but might not be able to lookup(ejb/ByEJB);

An EJB looking up another ejb that exists locally should be able to lookup(ejb/ByEJB)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: basic JNDI question.
 
Similar Threads
Looking up DataSource
Need help on Glassfish and EJB lookup
EJB lookup
local ejb reference from custom service
Finding resources