Solved

"jAVA:env/comp" JNDI lookups in Websphere 6.0.1

Posted on 2006-11-27
3
14,118 Views
Last Modified: 2013-12-10
Hi,
I am using websphere version 6 .0.1 am quite new to websphere. For JNDI lookups i give the full path example "ejb/test/someEJB" this works fine and i am able to run my small application. As soon as i append "java:env/comp" in front of the name websphere gives Namenot FoundException . It complains about java: not being set.
What is it that i need to do to make java: lookups.

2. How can i do lookups on environment variables defined in the web app. For example i want to store class name against a key as environment variable . I want to do a JNDI lookup and get the class instance.What server configuration is required to achieve it.

Thanks in advance to anyone who can enlighten me on this issue.
0
Comment
Question by:AMIT_SOOD
  • 2
3 Comments
 
LVL 10

Expert Comment

by:ECollin
ID: 18053159
hi,

Do you make these lookups from inside your web application ?

If you want to create environment entries in your web application and acces to them from your java code :
déclaration for your variable in the web.xml file :
<env-entry>
<description>welcome message</description>
<env-entry-name>greetings</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Welcome to the Inventory Control System</env-entry-value>
</env-entry>

java code :
javax.naming.Context ctx =
new javax.naming.InitialContext();
javax.naming.Context env =
ctx.lookup("java:comp/env");

// obtain the greetings message
//configured by the deployer
String str = (String) env.lookup("greetings");

2. If you want to obtain a reference to your ejb via an "indirection" use this :
in the web.xml :
<ejb-ref id="EjbRef_02">
   <ejb-ref-name>ejb/DualEntityRemoteHome</ejb-ref-name>
   <ejb-ref-type>Entity</ejb-ref-type>
   <home>dual.ejb.DualEntityRemoteHome</home>
   <remote>dual.ejb.DualEntityRemote</remote>
   <ejb-link>DualEJBModule01.jar#DualEntity</ejb-link>
</ejb-ref>
<ejb-local-ref id="EJBLocalRef_02">
   <ejb-ref-name>ejb/DualEntityLocalHome</ejb-ref-name>
   <ejb-ref-type>Entity</ejb-ref-type>
   <local-home>dual.ejb.DualEntityLocalHome</local-home>
   <local>dual.ejb.DualEntityLocal</local>
   <ejb-link>DualEJBModule01.jar#DualEntity</ejb-link>
</ejb-local-ref>

the lookup :
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("java:comp/env/ejb/DualEntityLocalHome");
or
DualEntityRemoteHome homeObject = (DualEntityRemoteHome)initCtx.lookup("java:comp/env/ejb/DualEntityRemoteHome");


Emmanuel
0
 

Author Comment

by:AMIT_SOOD
ID: 18058711
Hi Emmanuel,
Thanks for your reply.
I am doing what you just mentioned above but my question is i am not able to do lookups using "java:comp/env" .websphere complains about java not being set. example that you have given
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("java:comp/env/ejb/DualEntityLocalHome"); fails but if i do the samething in the following manner.
DualEntityLocalHome homeObject = (DualEntityLocalHome)initCtx.lookup("ejb/DualEntityLocalHome"); it succeeds.that means i can't do the following
javax.naming.Context env =
ctx.lookup("java:comp/env");
So the question is if websphere by default cannot lookup  "java:comp/env" what setting does the server require or in other words how do i configure it.

I hope you will be able to shed light on this issue.

Cheers
Amit Sood
0
 
LVL 10

Accepted Solution

by:
ECollin earned 500 total points
ID: 18059128
hi,

The java:comp/env context is reachable only from inside the web app. A servlet, a jsp or a single java class placed inside the web application can access this context.
A class outside the application (in another jvm for instance) will not be able to.

Emmanuel
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question