Tomcat

Overview

Tomcat is a very popular container and server for Java web applications and is being developed by a large community of the Apache Software Foundation (ASF). It enjoys great popularity in ecomomic and scientific disciplines and is considered to be robust, reliable and high-performant. In Java enterprise applications, it is mostly part of a J2EE application server like OpenEJB, Geronimo, JBoss or Glassfish and handles incoming requests to deployed web applications. Tomcat can also be used as module of an Apache HTTP Server (other modules exist for CGI or PHP support). Nevertheless, it is increasingly used as standalone web server.

If Tomcat is started as web server it will be bound to the specific TCP/IP address of the running computer and identified by a preconfigured port address where it is listening for incoming user requests. The transfer protocol on which requests are based is the HTTP protocol which allows to access any web application via web browser. The aim of the web container is to forward the requests to the intended web applications.

Various versions of Apache Tomcat are available which differ in the underlying architecture. Apache Tomcat implements the Java Servlet/ JSP specifications and each major version implements another specification whereas minor versions are mostly bugfixing and maintainance versions. E.g. both Tomcat versions 5.0 and 5.5 implement the Sun Servlet/JSP specifications 2.4/2.0 whereas version 6.0 implements the Servlet/JSP specifications 2.5/2.1 which lead to a significant jump in functionality. Further, each tomcat version is spitted into various modules that provide additional functionality, e.g, administration and monitoring modules and must be downloaded and installed separately. To run Tomcat as web container and server, the Core distribution is needed.

Windows installation

If you use Windows, you can download the Windows Server Installer version of the Core distribution. The installation is straight-forward. You should only take care, that the installation path to the Tomcat directory contains no whitespaces because then errors can occur when starting Tomcat as web server. We recommend a path something like that: C:\Programme\Apache\Tomcat.

The installation path to your Tomcat is referred to as CATALINA_HOME and is usually set as user/system variable. You can check this by opening the command prompt (Start, Ausfuehren and type cmd followed by pressing enter). Then type echo %CATALINA_HOME% and press enter. This command will print the installation path to your Tomcat directory on the console if CATALINA_HOME is set as user/system variable.

If Tomcat was successfully installed, you should notice a new icon in the Windows System Tray. With the help of this icon, you can start, stop and configure Tomcat.

If you started the server using the default configuration, you should be able to access the web server via URL http://localhost:8080 in your favourite web browser.

Linux installation

  1. Download the binary version, e.g. as tar.gz or zip, of the Core distribution.
  2. Extract it to a directory of your choice (e.g. extracting Tomcat version 5.5 to /opt/programs/ should result in a directoy /opt/programs/apache-tomcat-5.5)
  3. Change your directory to /etc/X11/Xsession.d/ and type as root touch 90environment. Then edit the file 90environment with your favourite text editor and insert the following:
    #installation path to our tomcat directory, 
    #in our example we use 5.5
    #Please set TOMCAT_HOME to your Tomcat installation directory    
    TOMCAT_HOME="/opt/programs/apache-tomcat-5.5"    
    CATALINA_HOME=$TOMCAT_HOME
                                    
    export TOMCAT_HOME CATALINA_HOME
                                    
    # path to our java installation directory
    #the following uncommented 3 lines must be done if
    #the 'javac' command is not found in the terminal
    #Please set JAVA_HOME to your Java SDK directory!!
    JAVA_HOME='/usr/java'
    PATH=$JAVA_HOME/bin:PATH
    export PATH JAVA_HOME
    
  4. Restart the operating system.

If you have done the previous steps, you should be able to start Tomcat by typing $CATALINA_HOME/bin/startup.sh followed by pressing enter. If Tomcat is really running, the URL http://localhost:8080 displays the Tomcat welcome page in any webbrowser of your choice. To stop Tomcat, you can use the command $CATALINA_HOME/bin/shutdown.sh.

Configuration

The configuration files of Tomcat are located in the CATALINA_HOME/conf directory and allow to change a couple of security settings.

  • Changing default port 8080 to any other:
    Edit the file server.xml in the CATALINA_HOME/conf directory with your favourite text editor. Find the Connector element in the XML file and change the port attribute value to your preferred port number. (It should not be a port number less than 1024 because they are reserved for other applications except you really know what you do;) ). E.g. the default Connector element can look like this:
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
                                
    Then you can change the port to 8089 on which Tomcat is listening for requests.
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector port="8089" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
                                
  • Setting username and password for Tomcat Manager:
    Edit the file tomcat-user.xml in the CATALINA_HOME/conf directory with your favourite text editor and add a new user with the role 'manager' and optionally 'tomcat'.
    <user username="Hugo" password="Boss" roles="manager,tomcat"/>
                                
    Now you can use the Tomcat Manager in your web browser with the username Hugo and the password Boss.

External libraries are located in the CATALINA_HOME/common/lib directory which are globally accessible by all deployed web applications.

  • Enabling Java Server Faces support:
    1. Download the latest version of the JSF Reference Implementation as archive file (named something like jsf-1_1_01.zip).
    2. Extract the file to a directory of your choice.
    3. Change to the extracted directory (named something like ../jsf-1_1_01) and go to the lib subdirectory.
    4. Copy all the jar files to the CATALINA_HOME/common/lib directory.
    5. If the CATALINA_HOME/common/lib directory does not contain the two jar files jstl.jar and standard.jar, copy them from the CATALINA_HOME/webapps/jsp-examples/WEB-INF/lib directory.
    6. From now on, Tomcat will be started with JSF and JSP support "out of the box".

By default, Tomcat's log files are stored in the CATALINA_HOME/log directory. The evaluation of these files can be very useful if errors occur during the deployment of your web application as well as during it's execution.

Reference

Additional information about Apache Tomcat can be found on the Official Tomcat website. The JSF reference implementation is published on the Oracle JSF website.