Tomcat installation and servlet development notes

These notes are intended to collect a number of key ideas and pointers for getting applications running in a Tomcat environment.

Contents:

1. Tomcat installation and test

#Installation

(These notes for installation on Windows XP.)

There are more detailed notes for installing Tomcat here: http://www.coreservlets.com/Apache-Tomcat-Tutorial/.

2. Configuration

#Configuration

See the comcat configuration reference pages at http://tomcat.apache.org/tomcat-5.5-doc/config/index.html.

There is also a good pagae about servlet configuration in general at http://java.sun.com/developer/Books/javaserverpages/servlets_javaserver/servlets_javaserver05.pdf.

3. Tomcat shutdown

Sometimes tomcat fails to respond to the shutdwon command. This appears to happen mainly when prior to initialisation (which may take a prohibitively long time or never be completed if tomcat is not given enough memory) or when tomcat is running but memory in the system is too low for a new JVM to be started. The solution is the command "killall -9 java" when run as the tomcat user seems to work reliably. This will send all processes with the name "java" signal 9, killing them with prejudice. Do not use this command if you have other running java programs you do not wish to kill.

4. Enabling servlet logging

#EnablingServletLogging

In Tomcat 5.5, servlet diagnostics do not automatically appear in the Tomcat logs. To obtain diagnostic information reported by servlet code through the Apache logging system, it may be necessary to configure additional log handlers as described in http://tomcat.apache.org/tomcat-5.5-doc/logging.html.

In summary:

log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=${catalina.home}/logs/tomcat.log log4j.appender.R.MaxFileSize=50MB log4j.appender.R.MaxBackupIndex=10 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n log4j.logger.org.apache.catalina=DEBUG, R }}}

The format of log output messages is controlled by the ...layout.ConversionPattern property value. See http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html for details.

The first line of the log4j.properties file above configures the root logger to send DEBUG level information to a new appender called 'R'. The following statements configure this appender. The final statement adjusts the level of information generated by classes in package org.apache.catalina

To suppress voluminous output from XML parsing, add the following line to the log4j configuration: {{{log4j.logger.org.apache.commons.digester=SEVERE, R }}}

5. Apache HTTPD Tomcat connector installation

#JKConnector

The connector known as mod_jk appears to be the favoured way to use Apache HTTPD to field HTTP requests that are handled by Tomcat. mod_jk2 was a later project, but has been relegated to "maintenance mode" due to lack of developer interest and configuration complexity.

The following notes refer to installation on Scientific Linux.

  1. Download source from http://www.apache.org/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.15/jakarta-tomcat-connectors-1.2.15-src.tar.gz

  2. Unpack the tar file into a working directory. We have used /opt/jakarta-tomcat-connectors/.

  3. Change to the root of the unpacked directory tree and run configure (look out for helpful files jk/BUILD.txt} and jk/native/BUILDING):

    • {{{cd /opt/jakarta-tomcat-connectors/jakarta-tomcat-connectors-1.2.15-src/jk/native

./configure --with-apxs=/usr/sbin/apxs }}}

}}}

  1. Run make:
Creative Commons License
The content of this wiki is licensed under the Creative Commons Attribution-ShareAlike 2.0 England & Wales Licence.

OSS Watch is funded by the Joint Information Systems Committee (JISC) and is situated within the Research Technologies Service (RTS) of the University of Oxford.