?
Solved

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

Posted on 2006-11-27
3
Medium Priority
?
14,152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

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 …
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

752 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