geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lasantha Ranaweera <>
Subject Re: Minimalistic example
Date Wed, 13 Sep 2006 07:06:29 GMT
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=""





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.

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="">

<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar xmlns="" 
xsi:schemaLocation="" version="2.1">

<display-name>Generated by XDoclet</display-name>


<!-- Session Beans -->
<session >
<description>Test EJB </description>



3. Create JAR files.
Hope EJB jar file would have a package structure something similar here.
|-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. ;)
|- META-INF/ application.xml


5. Refer EJB from Servlet as given below. (Casting to 
PortableRemoteObject is unnecessary. Anyway I am leaving it as you given)


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, 

MyTest test = home.create();
String newtime = test.getTime();
out.println("This is a new test, time from EJB =" + newtime + "<p>");
} catch (Exception e) {
out.println("Faild to get time from EJB<p>");

Hope this will help.

Lasantha Ranaweera

Mattias Malmgren wrote:
> Hi!
> I have prepared something for you here:
> 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

View raw message