Solved

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

Posted on 2006-11-27
3
14,095 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now