Project:Java/Tomcat 5 Guide

This guide provides information on the layout, usage, and other things related to Tomcat version 5.0.28, 5.5.x and later on Gentoo Linux.

Introduction
Some aspects of Tomcat on Gentoo are slightly different than how upstream handles it. This document aims to provide some information on how it differs. This document is based on Tomcat versions 5.0.28, 5.5.x and later. Versions of Tomcat older than 5.5.x should not be used, as it is discouraged by upstream. Which includes Tomcat 5.0.28. Only use that version if your application requires it. Otherwise please use 5.5.x or later when released.

The biggest initial difference on Gentoo is Tomcat being spread across multiple directories. That is because applications on Gentoo strive to comply FHS, in addition to Gentoo-specific standards. Another major differences is that Tomcat is compiled from source, along with the latest versions of any dependencies and bundled libraries, which will also be compiled from source. There are a number of smaller details, which will be covered in this guide.

This document will not cover Java Servlet Specifications, nor general Tomcat configuration. This document assumes the reader has a basic understanding of what a Java Web Application is, consists of, and basics of how to configure a container for the web application.

Standard Tomcat layout
The root directory of a typical Tomcat binary distribution is laid out as illustrated in the following listing:

Gentoo Tomcat layout
To comply with FHS and Gentoo standards, Tomcat has been dissected and installed into the following locations:

Configuration files
In addition to simply moving the Tomcat directory under. There is a Gentoo-specific Tomcat configuration file, which contains Tomcat variables that are sourced by. These variables are:


 * JAVA_HOME : default is to be set to $(java-config --jdk-home). Changing this variable allows Tomcat to run with a VM other than the system VM
 * CATALINA_HOME : default is
 * CATALINA_BASE : default is
 * CATALINA_USER : default is tomcat
 * CATALINA_LIBDIR : default is typically
 * CLASSPATH : default is ${CATALINA_LIBDIR}
 * CATALINA_TMPDIR : default is /var/tmp/tomcat-*
 * TOMCAT_START : default is "start", with alternatives being "debug", "start -security", "debug -security", or "jpda start"
 * TOMCAT_STOP : default is "stop"
 * CATALINA_OPTS : not set by default, can be used to pass options to Java or Tomcat

The Gentoo init script is also installed into, at. Tomcat on Gentoo no longer uses or modifies.

Web applications
The contains a symlinks to other Tomcat directories, and the  directory where actual web applications go. This directory serves as the hub and is referenced by Tomcat as the.

Gentoo Tomcat base and webapp location:

Runtime files
These directories hold logs, temp, and working files used by Tomcat.


 * - Tomcat's temporary directory
 * - Tomcat's working directory, where JSPs Java sources and resulting class files live
 * - Tomcat's logging directory

USE flags
Tomcat's USE flags are not any different from USE flags for any package on Gentoo. Most are self-explanatory like doc, sources, and test. They are for documentation, sources, and running unit tests, correspondingly.

The admin USE flag determines if Tomcat's admin webapp will be built and installed. Using this flag also adds struts as a dependency to Tomcat.

The examples USE flag should be used for anyone new to Tomcat, Java Web Application development, or just about anything beyond deploying existing applications. When set, the examples USE flag will install the example web applications. Most all can safely ignore this USE flag, unless you are starting out.

The  USE flag will build a Java 1.5 byte code version of Tomcat 5.5.x. It will also reduce a considerable amount of dependencies since mx4j is dropped as a dependency when the   USE flag is enabled.

Emerge
Once you have the desired USE flags set in or  and added packages names to  it's time to actually install Tomcat. Tomcat, like every other package on Gentoo, is installed by doing:

Configuration
Depending on what Tomcat will be used for, one may or may not need to finely configure Tomcat. If Tomcat is just a dependency of another application, one might be able to simple start Tomcat, and request the application via a browser or etc at http://127.0.0.1:8080/.

For most others, particularly developers, running more than one site under Tomcat, or etc. will need to edit Tomcat's main configuration file. The syntax of that file, and configuration of Tomcat is beyond the scope of this document. Please refer to Tomcat documentation for more information.

Using a specific VM
By default, Tomcat will use the system VM controlled by java-config as-per the JAVA_HOME variable in. One can change that variable to point to any VM that is capable of running Tomcat. Then, when Tomcat is started, it will use the specified VM.

Logging
With 5.5.x Logging has changed a bit. Tomcat no longer uses log4j by default. Applications can still use log4j, however the jars have to be put onto the classpath manually. Log4j is not used by a Tomcat install by default, same as upstream. For more information please refer to Tomcat's documentation on logging. Despite this change log4j is still a compile time dependency for now. http://jakarta.apache.org/commons/logging/tech.html

OpenRC
Tomcat is started and stopped the same as any service on Gentoo:

Tomcat's standard web applications
By default we do not install Tomcat's admin, docs, or examples web application. We do, however, install Tomcat's ROOT and manager applications. However per upstream Tomcat policy, no usernames or passwords are configured by default. should be modified to add users:


 * http://127.0.0.1:8080/
 * http://127.0.0.1:8080/manager/html/

Troubleshooting
If you have problems, please stop and think if the problem is Gentoo related, or Tomcat specific. If you are not sure, please start with the Gentoo Java community and Team, which can be reached via the gentoo-java mailing list, or IRC channel on Freenode. Please file and report Gentoo related bugs, feature enhancement requests, etc. to http://bugs.gentoo.org/

Missing
Currently the is not build by default. To build that jar Tomcat robs .java source files from 3 other commons packages, collections, pool, and dbcp. There is no clean solution to compiling this jar at this time. Suggestions, patches, or any assistance on compiling that jar is greatly appreciated.

There are alternatives to this jar. You can use, or use the factory provided by most all jdbc drivers.

Future possibilities for Tomcat on Gentoo
These are some features which are either in consideration, under development, or are only a dream. Ideally to be implemented in the order listed below.


 * Gentoo Web Application integration support per GLEP 11
 * Documentation on Tomcat's connectors and using them to connect to Apache on Gentoo Linux.
 * Replace init script with one developed by a Tomcat developer http://www.webdroid.org:8080/repo/viewcvs.cgi/tomcat-package/trunk/bin/
 * Modify Tomcat init script or ebuild to use JSVC so Tomcat can run on unprivileged ports. This might not happen, as in there are other ways to do this. We are working with upstream on this but are far from an ideal solution. http://bugs.gentoo.org/show_bug.cgi?id=75224