permaculture playing cards
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
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "basic JNDI question." Watch "basic JNDI question." New topic

basic JNDI question.

peter cooke
Ranch Hand

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


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.

peter cooke
Ranch Hand

Joined: Mar 16, 2004
Posts: 317
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:
subject: basic JNDI question.
It's not a secret anymore!