Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-27
3
Medium Priority
?
14,162 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

598 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