File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes java:comp/env - vs. - Global JNDI lookup - What is the difference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "java:comp/env - vs. - Global JNDI lookup - What is the difference?" Watch "java:comp/env - vs. - Global JNDI lookup - What is the difference?" New topic
Author

java:comp/env - vs. - Global JNDI lookup - What is the difference?

Anirudh Gupta
Ranch Hand

Joined: Dec 08, 2010
Posts: 47

O'Reily EJB 3.1, Chapter 18 - Interceptors, Section Custom Injection Annotations.

The EJB specification has a bunch of annotations for injecting Java EE resources, services, and EJB references into
your bean classes. Some application servers or applications like to use JNDI as a global registry for configuration or for
non-Java EE services. Unfortunately, the specification defines no way to inject something directly from global JNDI into your beans.


With respect to the above statement(s) I had a train of thoughts which led me to the question,

What is the fundamental difference between "java:/comp/env" and "Global JNDI". Aren't they both contexts within the same JVM?
How are they different?


I realize that "Global JNDI" could be anything(as in any context) and I have purposely left it undefined in the question here. I am of course
referring to EJB lookup and resource lookup. The other question in my mind is,

Can I lookup one bean from another by using the "java:comp/env" context? What are the various conditions under which I can or cannot
do this?


Regards,
Anirudh
Cosmin Nicolae Vacaroiu
Ranch Hand

Joined: Feb 10, 2011
Posts: 52

"java:comp/env" is used mainly to do manual lookup on it. Each EJB has its own "java:comp/env".


SCJP 6 (93%), SQL Expert 11g (95%), SCWCD 6 (84%), OCE-EJBD 6 (98%), OCE-JPAD 6 (93%)
Herman Pomstra
Greenhorn

Joined: Aug 17, 2011
Posts: 7

Or look at: http://stackoverflow.com/questions/7458114/what-is-the-relationship-between-javacomp-env-and-javaglobal
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java:comp/env - vs. - Global JNDI lookup - What is the difference?