# 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.

- First implementation is Tomcat 4.1.x which is used as servlet container.
- Second implementation is with web container service Jetty 4.2.x

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:

- `org.objectweb.jonas.web.catalina41.CatalinaJWebContainerServiceImpl` (It is the default value)

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

Configure Tomcat with a JOnAS realm. Check the security HowTo.

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`

You can found a server.xml example in `JONAS_ROOT/conf/server.xml`

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.