This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

basic JNDI question.

 
peter cooke
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic