• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejb jndi name confused me

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
i am a beginner to ejb,in my book,somtimes it use following fomat to lookup the home:

Object objref=initial.lookup("java:comp/env/ejb/MyEjb");

but sometimes,it use another format as following:

Object objref=initial.lookup("MyEjb");

what's the difference between them?
and when use what format?
thanks for any helps!
 
Tualha Khan
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I maybe wrong, but the former is used for command line applications or applications and the latter is used for web apps.
Any Suggestions here???
Thanks & Bye,
Tualha Khan
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They both work. If I define a reference to an EJB in my weblogic-jar.xml file like this:
<ejb-reference-description>
<ejb-ref-name>ejb/sr/employeeSearch</ejb-ref-name>
<jndi-name>EmployeeSearch</jndi-name>
</ejb-reference-description>
..then I could use:
Object objref = initial.lookup("java:comp/env/ejb/sr/employeeSearch");
..or:
Object objref = initial.lookup("EmployeeSearch");
..to find the home interface.
In the first case, you are using the default jndi context "java:comp/env/" + ejb-ref-name as defined in weblogic-jar.xml. In the second case, you are using the actual JNDI name of the EJB. The first case is the recommended approach.
SAF
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for your instruction!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic