This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes JNDI Name not found exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI Name not found exception" Watch "JNDI Name not found exception" New topic
Author

JNDI Name not found exception

Chandra S Marappa
Greenhorn

Joined: Apr 26, 2005
Posts: 19
I am using weblogic server.

The following lines of code is what i am using in a jsp,
-------------------------In jsp -----------------------
javax.naming.Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(javax.naming.Context.PROVIDER_URL,
"t3://localhost:7001");
ctx = new javax.naming.InitialContext(ht);
EtsBean bean = (EtsBean)ctx.lookup("ejb/EtsHome");

to retrieve the context name

my deployment descriptors contains the following....
-------------------------In ejb-jar.xml -----------------------
<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN'
'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

<ejb-jar>
<enterprise-beans>
<!-- A minimal session EJB deployment -->
<session>
<ejb-name>EtsHome</ejb-name>
<jndi-name>ejb/EtsHome</jndi-name>
<home>EdenBaseBean.etsEJB.EtsHome</home>
<remote>EdenBaseBean.etsEJB.Ets</remote>
<ejb-class>EdenBaseBean.etsEJB.EtsBean</ejb-class>
<!-- or Stateless -->
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<!-- Assembly Descriptor -->
<assembly-descriptor></assembly-descriptor>
</ejb-jar>

-------------------In weblogic-ejb-jar.xml ----------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">

<weblogic-ejb-jar>
<description>Stateful Session Bean Example</description>
<weblogic-enterprise-bean>
<ejb-name>EtsHome</ejb-name>
<stateful-session-descriptor></stateful-session-descriptor>
<reference-descriptor></reference-descriptor>
<jndi-name>ejb/EtsHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

This is the following error i am getting on the console,
-----------------------Error Trace ---------------------------
javax.naming.NameNotFoundException: While trying to lookup 'ejb.EtsHome' didn't find subcontext 'ejb' Resolved ; remaining name 'ejb/EtsHome'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:897)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:225)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:256)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:357)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at jsp_servlet.__selectestimatesfield._jspService(__selectestimatesfield.java:2068)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

--------------------------------------------------

Can anyone help me out in resolving this problem.....
Thanks in advance for your kind help...


Regds<br />---------------<br />Chandru
seshu Palamanti
Ranch Hand

Joined: Jul 03, 2004
Posts: 59
Looks like you are using Weblogic try looking up the JNDI tree on the server console before you run your client. It should be under servers.

Also Check your code i use this one works fine.
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.SECURITY_PRINCIPAL, user);
h.put(Context.SECURITY_CREDENTIALS, password);

Object homeObject = context.lookup("ejb/MyEJB");
MyEJBhome = (MyEJBHome) PortableRemoteObject
.narrow(homeObject, MyEJBHome.class);
remote = home.create();

Hope this helps.
paresh vernekar
Ranch Hand

Joined: Jul 10, 2006
Posts: 52
HI Chandru,
Has your problem been solved?


I think when you do a lookup you should use the following:
context.lookup("java:comp/env/ejb/MyEJB")

Let me know if this solves your problem

Regards,
Paresh Vernekar
paresh vernekar
Ranch Hand

Joined: Jul 10, 2006
Posts: 52
HI Chandru,
Has your problem been solved?


I think when you do a lookup you should use the following:
context.lookup("java:comp/env/ejb/MyEJB")

Let me know if this solves your problem

Regards,
Paresh Vernekar
Chandra S Marappa
Greenhorn

Joined: Apr 26, 2005
Posts: 19
The problem is still persisting...

could anyone tell me whether the DD's are correct or not andif wrong what is the changes i have to do....

if anyone could send me a sample for using an EJB(deploying in WEBlogic 8.1), it would be so nice....


Thanks in advance....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JNDI Name not found exception