Integrating Tomcat and JOnAS

Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. This guide describes how to integrate JOnAS with Tomcat from Apache.

Since JOnAS 2.6 provides a full J2EE application server, Tomcat may be used with JOnAS as Web container. This functionnality is set up via the JOnAS web container service.
At this time Tomcat 4.1.x and Jetty 4.2.x are supported as implementation of JOnAS web container service.
Note that in earlier versions of JOnAS a service tomcat was provided with two implementations one for Tomcat 3.3.x and one for Tomcat4.0.x. This service tomcat is now deprecated because it was not compliant to J2EE specification.
So now, Tomcat 3.3.x is no more supported with JOnAS (except through the deprecated servicetomcat) .

In the JOnAS J2EE server you will be able to run your beans inside EJB containers via the ejb service or ear service while you will be able to run your servlets or JSPs via the web container service or ear service. JOnAS will be used to run your beans inside EJB containers while Tomcat will be used to run your servlets or JSPs. Inside these servlets or JSPs, you will be allowed to access remotely beans inside the JOnAS EJBServer.

For the cases where security is needed, Tomcat will be used also for user authentication. Refer to the security guide for more information on how to use security with JOnAS and Tomcat.

Here after are described the following steps to configure JOnAS and Tomcat to make them working together.

  1. Installing Tomcat
  2. Configuring Tomcat for JOnAS
  3. Structuring your Web Application

Installing Tomcat

  1. Download Tomcat at Apache site
    At this time tomcat 4.1.x family has been tested successfully with JOnAS.
  2. Install Tomcat by unzipping the download file and put it in a specific directory. This directory will be referred as $CATALINA_HOME.
    If you want to share a single copy of Tomcat 4 among multiple users on the same server, you must configure a CATALINA_BASE environment variable (in addition to CATALINA_HOME) that points to a directory that is unique to your instance. Set both variables in your environment and export them.
  3. On Windows, set the JAVA_HOME variable in your environment to your JDK installation directory.

Configuring Tomcat for JOnAS

Since JOnAS 2.6 a new JOnAS service web is provided for launching a servlet container inside the JOnAS JVM.
At this time, two implementations of this service are provided.


All you have to do is to add web in the jonas.services property of jonas.properties file and to set the jonas.service.web.class property of jonas.properties file to:

Then you configure Tomcat as usual by updating if needed the $CATALINA_HOME/conf/server.xml or the $CATALINA_BASE/conf/server.xml.

If you want to customize a web application that will be deployed by the web container service or the ear service you can do this in the server.xml file by setting a <Context/> element with attribute className set to org.objectweb.jonas.web.catalina41.JOnASStandardContext

Here is a simple server.xml file that can be used:

<Server port="8005" shutdown="SHUTDOWN" debug="0">

  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Tomcat-in-JOnAS">

    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="60000"/>


    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               port="8009" minProcessors="5" maxProcessors="75"
               acceptCount="10" debug="0"/>

    -->
    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Standalone" defaultHost="localhost" debug="0">

      <!-- Global logger unless overridden at lower levels -->

      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="catalina_log." suffix=".txt"
              timestamp="true"/>

      <!-- Because this Realm is here, an instance will be shared globally -->

     <Realm className="org.objectweb.security.tomcat.interceptor.SecurityCtxInterceptor41" /> 

      <!-- Define the default virtual host -->
      <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" 
                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
                 pattern="common"/>
        <Logger className="org.apache.catalina.logger.FileLogger" 
                 directory="logs"  prefix="localhost_log." suffix=".txt"
	        timestamp="true"/>
        <Context className="org.objectweb.jonas.web.catalina41.JOnASStandardContext" path="/earsample" docBase="earsample" debug="0" reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="YYYY." suffix=".ttt"
        	  timestamp="true"/>
        </Context>
      </Host>

    </Engine>

  </Service>

</Server>

Of course this is only a subset of what is possible to configure in Tomcat. For more information have a look at Tomcat configuration documentation

Structuring your Web Application

How to use servlets and JSPs is explained in the Developing Web Components or J2EE Application Programmer's Guide chapters of the online JOnAS documentation.