wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Problems with EJB3.0... (continued) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problems with EJB3.0... (continued)" Watch "Problems with EJB3.0... (continued)" New topic
Author

Problems with EJB3.0... (continued)

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
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|#]
Fabian Gutierrez
Greenhorn

Joined: Aug 15, 2004
Posts: 22
Keith,

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

regards,


SCJP 1.4, SCWCD 1.4, SCBCD 5, SCJD 5
Shailesh Kini
Ranch Hand

Joined: Oct 17, 2001
Posts: 153
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.


Shailesh Kini.
 
GeeCON Prague 2014
 
subject: Problems with EJB3.0... (continued)