• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problems with EJB3.0... (continued)

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I posted on here a couple of days ago about problems I was having deploying EJB3.0 on teh Sun WebApp 9.0.
Whilst I've mnaged to deploy my EJB & Client (SimpleServlet) as seperate modules (web.war & ejb.jar) I am still
having trouble getting the Servlet to connect with the EJB...

I have chosen the XML deployment descriptor route over Annotation because it seems easier for changing
(especially during development) also I'm not keen on having this sort of info in the actual code.

Below are (what I think) are the relivent files and code bits, could someone please help me understand why the
Servlet is throwing the 'NameNotFoundException' Exception when connecting to the SampleModel bean.

Any help would be Cheers

KS



SampleServlet
-------------
try {
InitialContext cxt = new InitialContext();
SampleRemote remote = (SampleRemote)cxt.lookup("java:comp/env/ejb/SampleModel");
System.out.println("Name: "+remote.getName());
} catch (NamingException NEx) {
System.out.println("Naming Exception: "+NEx);
}


web.xml
-------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>SampleServlet</servlet-name>
<servlet-class>com.myclient.servlets.SampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SampleServlet</servlet-name>
<url-pattern>/web/SampleServlet</url-pattern>
</servlet-mapping>
<ejb-ref>
<ejb-ref-name>ejb/samplemodel</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.myproject.sample1.SampleLocal</home>
<remote>com.myproject.sample1.SampleLocal</remote>
<ejb-link>SampleBean</ejb-link>
</ejb-ref>
</web-app>


ejb-jar.xml
-----------
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee" version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<description>
Sample
</description>
<enterprise-beans>
<session>
<description>
Sample Bean for testing
</description>
<display-name>
SampleBean
</display-name>
<ejb-name>SampleModel</ejb-name>
<business-local>com.myproject.sample1.SampleLocal</business-local>
<business-remote>com.myproject.sample1.SampleRemote</business-remote>
<ejb-class>com.myproject.sample1.SampleModel</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>


sun-ejb-jar.xml
---------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 9.0 EJB 3.0//EN'
'http://www.sun.com/software/dtd/appserver/sun-ejb-jar_3_0-0.dtd'>
<sun-ejb-jar>
<display-name>Sample</display-name>
<enterprise-beans>
<unique-id>1</unique-id>
<ejb>
<ejb-name>SampleModel</ejb-name>
<jndi-name>samplemodel</jndi-name>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
</xml>


server.log
----------
[#|2007-10-10T11:37:38.400+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=11;_ThreadName=httpWorkerThread-8080-0;|
Naming Exception: javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/SampleModel|#]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keith,

the sun application server has a jndi tree explorer, there you can check what is the actual path for that bean.

regards,
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Keith,

web.xml and ejb-jar.xml looks OK. However the text in <jndi-name> in sun-ejb-jar.xml does not match with <ejb-ref-name> in web.xml. Can you please change the sun-ejb-jar.xml <jndi-name>samplemodel</jndi-name> to <jndi-name>ejb/samplemodel</jndi-name>.

I am not sure if the jndi names are case sensitive but it always helps to make sure to use the same case when looking up for the jndi name in the servlet as defined in web.xml and sun-ejb-jar.xml.
reply
    Bookmark Topic Watch Topic
  • New Topic