Hi Mattias,
Following are my comments regarding this sample. I think step 1 to 3 you
might have already done. Anyway I am going to put it to clarity.
1. web.xml
You need to add ejb-ref element to the given web.xml as given in below.
Missing geronimo-web.xml in will give a warning. But anyway it will
work. :)
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<display-name>MyTestServlet</display-name>
<servlet-name>MyTestServlet</servlet-name>
<servlet-class>MyTestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyTestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
<ejb-ref>
<ejb-ref-name>ejb/MyTest</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>MyTestHome</home>
<remote>MyTest</remote>
<ejb-link>MyTestBean</ejb-link>
</ejb-ref>
</web-app>
2. Can't find openejb-jar.xml and ejb-jar.xml in your document.
I can't find the openejb-jar.xml and ejb-jar.xml for the ejb.jar file.
It would be some thing like this given in the below.
openejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
<dep:environment
xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">
<dep:moduleId>
<dep:groupId>samples</dep:groupId>
<dep:artifactId>my-test-ejb</dep:artifactId>
<dep:version>1.0</dep:version>
<dep:type>car</dep:type>
</dep:moduleId>
<dep:dependencies/>
<dep:hidden-classes/>
<dep:non-overridable-classes/>
</dep:environment>
<enterprise-beans>
<session>
<ejb-name>MyTestBean</ejb-name>
<jndi-name>MyTestBean</jndi-name>
</session>
</enterprise-beans>
</openejb-jar>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar 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/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session >
<description>Test EJB </description>
<ejb-name>MyTestBean</ejb-name>
<home>MyTestHome</home>
<remote>MyTest</remote>
<ejb-class>MyTestBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
3. Create JAR files.
Hope EJB jar file would have a package structure something similar here.
my-test-ejb.jar
|-META-INF/ openejb-jar.xml
|-META-INF/ ejb-jar.xml
|- <ejb classes>
4. Create an EAR with following structure. Note I have changed WAR
archive as my-test-web.war. ;)
my-test.ear
|- META-INF/ application.xml
my-test-web.war
my-test-ejb.jar
application.xml
5. Refer EJB from Servlet as given below. (Casting to
PortableRemoteObject is unnecessary. Anyway I am leaving it as you given)
MyTestServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.test.ejb.MyTest;
import com.test.ejb.MyTestHome;
public class MyTestServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("This is a test, time in servlet =" + new
java.util.Date().toString() + "<p>");
// Put the code here that can get the time from the EJB
// That code might look somthing like this?
try {
Context initial = new InitialContext();
Object objref = initial.lookup("java:comp/env/ejb/MyTest");
MyTestHome home = (MyTestHome)PortableRemoteObject.narrow(objref,
MyTestHome.class);
MyTest test = home.create();
String newtime = test.getTime();
out.println("This is a new test, time from EJB =" + newtime + "<p>");
} catch (Exception e) {
e.printStackTrace();
out.println("Faild to get time from EJB<p>");
}
}
}
Hope this will help.
BR,
Lasantha Ranaweera
Mattias Malmgren wrote:
Hi!
I have prepared something for you here:
http://www.freefarm.se/geronimohelp.htm
Best regards / Mattias
At 15:01 2006-09-12, you wrote:
Hi Mattias,
I would like to help you on this matter. Post your files to the
community.
Regards,
Lasantha Ranaweera
Mattias Malmgren wrote:
Hello!
I have coded Java for 10 years, I know who to write Servlets and so
on. Now I would like to write som EJBs and depoy them on geronimo. I
can compile my EJBs, but the hard task is to make a ear-file and
deploy. I have looked at the Bank-exemaple in the documentation, but
it is to compex. Is there a more minimalistic example?
Best regards / Mattias