File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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 agree. Here's the link:
subject: JNDI question in JBoss environment
Similar Threads
Lookup problem with EJB3
Question: ejb-ref with ejb3.0 and jboss-4.2.0.GA
Problem deploying sample HelloWorld Bean in JBoss 4.2.1 GA
Simple EJB3 session beans not deploying in JBOSS6
javax.naming.NameNotFoundException: javax.transaction.UserTransaction not bound