
 OpenEJB Tomcat Integration
 |
Introduction OpenEJB per Tomcat instance OpenEJB per webapp OpenEJB Tomcat resource factory How to make the document even more helpful resource
Introduction
There are a few approaches to integrate OpenEJB and Jakarta Tomcat.
The difference between them is in the visibility of EJBs (deployed onto OpenEJB) amongst web applications (deployed onto Tomcat).
The term visibility means what classloaders handle loading of the EJBs.
OpenEJB configuration by its visibility
OpenEJB per Tomcat instance
Configure OpenEJB per Tomcat instance requires the following steps:
- Copy the war/openejb-loader-1.0-SNAPSHOT.war into the webapps dir of a running Tomcat install
| Under Unix |
$ cd $OPENEJB_HOME
$ cp war/openejb-loader-1.0-SNAPSHOT.war $CATALINA_HOME/webapps
|
or
| Under Windows |
c:/> cd %OPENEJB_HOME%
%OPENEJB_HOME%> cp war/openejb-loader-1.0-SNAPSHOT.war %CATALINA_HOME%/webapps
|
- Update the openejb.home init param (inside the WEB-INF/web.xml file) to point to where OpenEJB was installed.
If OpenEJB has been built from the source you can skip it (during the build procedure it is updated automatically)
| Under Unix |
$ cd $CATALINA_HOME/webapps
$ jar -xvf openejb-loader-1.0-SNAPSHOT.war WEB-INF/web.xml
...edit WEB-INF/web.xml...
$ jar -uvf openejb-loader-1.0-SNAPSHOT.war WEB-INF/web.xml
$ rm -rf WEB-INF
|
or
| Under Windows |
c:/> cd %CATALINA_HOME%/webapps
%CATALINA_HOME%/webapps> jar -xvf openejb-loader-1.0-SNAPSHOT.war WEB-INF/web.xml
...edit WEB-INF/web.xml...
%CATALINA_HOME%/webapps> jar -uvf openejb-loader-1.0-SNAPSHOT.war WEB-INF/web.xml
%CATALINA_HOME%/webapps> rmdir /S /Q WEB-INF
|
- Create the temp directory under Tomcat's home directory
| NOTE | | This is because the beans that's been successfully validated are deployed. During validation OpenEJB creates temporary files under the temp.dir directory, which is overriden by Tomcat to its temp directory. Unfortunatelly, the directory doesn't exist and needs to be created manually. |
|
- Deploy your webapps that are using the beans deployed onto OpenEJB
- Start up Tomcat and have fun with the EJBs
OpenEJB per webapp
Configure OpenEJB per webapp requires the following steps:
- Copy the openejb-loader-*.jar into the WEB-INF/lib directory of the webapp that is to use EJBs deployed onto OpenEJB
- Add the loader servlet definition to the WEB-INF/web.xml file of the webapp with a valid value for openejb.home init-param.
<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>...define OPENEJB_HOME here...</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
|
Should you define other OpenEJB configuration settings use another <init-param> stanza. It's just for that. These parameters are directly passed to OpenEJB at initialization of the servlet. Think about the loader servlet as a bridge between OpenEJB's world (EJBs) and Tomcat's world (servlets, JSPs).
At startup OpenEJB prints out all of the configuration settings to Tomcat logs:
INFO: Installing web application at context path /openejb from URL file:C:\webapps\openejb
OpenEJB init-params:
param-name: openejb.home, param-value: c:\openejb
param-name: openejb.configuration, param-value: conf\openejb.cfg
param-name: openejb.base, param-value: c:\webapps\openejb\WEB-INF\openejb
param-name: openejb.loader, param-value: tomcat-webapp |
- Start up Tomcat and have fun with the EJBs
OpenEJB Tomcat resource factory
Read about it here.
How to make the document even more helpful resource
This document is a starting point for using OpenEJB in Tomcat and will evolve based
on user contributions. If you wish to contribute to this document, please email the
text to the OpenEJB User list.
|