Hi,

Finally, I made it. Another step forward to enhance the area of having OpenEJB embedded and configured separately per webapp. The changes are enhancements to Dave's changes (and I hope they don't break anything in what was there besides logging).

The just-committed changes to openejb1 branch contain:

1/ OPENEJB_BASE and OPENEJB_HOME work as their Tomcat counterparts

It's possible to define OPENEJB_BASE to any directory and have them almost everything you need in it. The rest will be found in OPENEJB_HOME. Don't expect, however, that when lib directory is in both, contents will be merged, only OPENEJB_BASE/lib is taken into account.

and here's what they broke and where *you* can help:

2/ logging (log4j) doesn't work

When Tomcat starts up, log4j chokes it's not able to find its configuration file. It's because OpenEJB tries to keep its properties internally instead of setting System ones.

3/ documentation

OpenEJB needs more documentation. I'm writing down what's changed. Sample webapps are on their way (they're supposed to show the integration really works).

To get you started do the following:

*) Build OpenEJB from the latest CVS sources
*) Download Jakarta Tomcat 5.0.25
*) Create a directory - mywebapp - underneath webapps (inside Tomcat installation dir) - it's your brand new webapp
*) Create WEB-INF directory underneath mywebapp webapp home dir
*) Copy target/openejb-1.0-SNAPSHOT/lib/openejb-loader-1.0-SNAPSHOT.jar to $CATALINA_HOME/webapps/mywebapp/lib directory
*) Create web.xml (underneath WEB-INF of mywebapp webapp) with the following contents:


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>

  <display-name>OpenEJB Test WebApp</display-name>

  <servlet>
    <servlet-name>loader</servlet-name>
    <servlet-class>org.openejb.loader.LoaderServlet</servlet-class>

    <init-param>

      <param-name>openejb.loader</param-name>
      <param-value>tomcat-webapp</param-value>

    </init-param>

    <init-param>

      <param-name>openejb.home</param-name>

<param-value>c:\projects\openejb-openejb1\target\openejb-1.0-SNAPSHOT</param-value>

    </init-param>

    <init-param>

      <param-name>openejb.base</param-name>

<param-value>CATALINA_HOME\webapps\mywebapp\WEB-INF\openejb</param-value>

    </init-param>

    <init-param>

      <param-name>openejb.configuration</param-name>
      <param-value>conf\openejb.cfg</param-value>

    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>
</web-app>

Don't forget to change CATALINA_HOME in openejb.base param-name's value to the full path of Tomcat home directory.

 *) Create index.jsp in the mywebapp webapp home dir:

<%
    java.util.Properties p = new java.util.Properties();

p.put("java.naming.factory.initial", "org.openejb.client.LocalInitialContextFactory");

    javax.naming.InitialContext ctx = new javax.naming.InitialContext( p );

Object obj = ctx.lookup("client/tests/stateless/BasicStatelessHome");
%>
<%= obj %>
<%
org.openejb.test.stateless.BasicStatelessHome home = (org.openejb.test.stateless.BasicStatelessHome) obj;
obj = home.create();
org.openejb.test.stateless.BasicStatelessObject bean = (org.openejb.test.stateless.BasicStatelessObject) obj;
%>
<p>
<%= bean.businessMethod( "OpenEJB" ) %>


*) Create WEB-INF/openejb/conf/openejb.cfg file with the default configuration file (copied from target/openejb-1.0-SNAPSHOT/conf/openejb.conf). It's to show how OPENEJB_BASE works.

 *) Start up Tomcat

 *) Open up your browser and point it to http://localhost:8080/mywebapp

That's it! Simple? It should be :)

(no it doesn't work? Please let me know. I doubt if it doesn't :))

Best,
Jacek

Reply via email to