This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes JNDI question in JBoss environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "JNDI question in JBoss environment" Watch "JNDI question in JBoss environment" New topic

JNDI question in JBoss environment

Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
I have an EJB deployed on JBoss 4.0.2 application server. I wrote a stand alone java client to access the bean, but I'm getting unexpected behavior.

If i try to lookup the bean this way:

everything works fine. However, if I try to lookup the bean in this way:

I get the following error and stack trace:

Any ideas on why this may be happening?

SCJP 1.4, SCWCD J2EE 1.4, SCJD J2SE 1.5, SCBCD J2EE 1.3, SCDJWS (In Progress)
Daniel Rhoades
Ranch Hand

Joined: Jun 30, 2004
Posts: 186
This works for me in JBoss:

InitialContext iniCtx = new InitialContext();
Context ejbCtx = (Context) iniCtx.lookup("java:comp/env/ejb");
Object obj = ejbCtx.lookup("Fortune");

Drinking more tea is the key...
Michael Valentino
Ranch Hand

Joined: Nov 01, 2005
Posts: 96
A lookup such as the one you've posted works for me as well, but only when the client to the EJB is running in the same container as the EJB. Otherwise I get a "comp not bound" message in an exception. I'm not a JNDI guru, but I'm guessing it has to do with the JNDI namespaces - the EJB running on one instance of the JVM is in one JNDI namespace, while the client running in another instance of the JVM is in a different namespace. Doing a global lookup ( ctx.lookup("/ejb/myEJB"); ) works while doing a specific ( ctx.lookup("java:comp/env/ejb/myEJB") ) will not due to the difference in namespaces. Is this correct? If not, what am I misunderstanding?

Thank you for your help.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: JNDI question in JBoss environment
It's not a secret anymore!