Bristle Software Apache Tomcat Tips

This page is offered as a service of Bristle Software, Inc.  New tips are sent to an associated mailing list when they are posted here.  Please send comments, corrections, any tips you'd like to contribute, or requests to be added to the mailing list, to tips@bristle.com.

Table of Contents:

  1. Deploying A Webapp
  2. Auto-Reloading A Webapp
  3. Auto-Reloading All Webapps
  4. Auto-Reloading Webapps More Often

Details of Tips:

  1. Deploying A Webapp

    Last Updated: 1/7/2006
    Applies to: Tomcat 5.0.28+

    There are several ways to deploy a Webapp in Tomcat:

    1. Create a context configuration file for the Webapp in the Tomcat directory:

          .../conf/Catalina/localhost

      with a name like:

          mywebapp.xml

      and contents like: 

          <Context  docBase="/home/fred/bristle/webapps/mywebapp/web" 
                          path="/mywebapp"
          ></Context>

      pointing to the directory where the webapp resides.

    2. Create such a context configuration file for the Webapp in the Tomcat directory:

          .../webapps

    3. Create an apps.xml context configuration file for multiple apps:

         .../conf/Catalina/localhost/apps.xml

      with contents like: 

          <?xml version="1.0" encoding="ISO-8859-1"?>
          <webapps>
            <Context  docBase="/home/fred/bristle/webapps/mywebapp/web" 
                            path="/mywebapp"
            ></Context>
            <Context  docBase="/home/fred/bristle/webapps/otherapp/web" 
                            path="/otherapp"
            ></Context>
          </webapps>

    4. Add a similar <Context> element to the main Tomcat server.xml file:

          .../conf/server.xml

    5. Copy the entire contents of the directory where the webapp resides to the Tomcat directory:

          .../webapps

    6. Copy the Webapp WAR file to the directory:

          .../webapps

    --Fred

  2. Auto-Reloading A Webapp

    Last Updated: 1/7/2006
    Applies to: Tomcat 5.0.28+

    To cause Tomcat to check for and load updated code for a Webapp, edit the <Context> element of the context configuration file, setting the reloadable attribute of the Context element to "true", as:

            <Context  docBase="/home/fred/bristle/webapps/mywebapp/web" 
                            path="/mywebapp"
                            reloadable="true"
            >
            </Context>

    --Fred

  3. Auto-Reloading All Webapps

    Last Updated: 1/7/2006
    Applies to: Tomcat 5.0.28+

    To cause Tomcat to check for and load updated code for all Webapps by default, add a <DefaultContext> element to the main Tomcat server.xml file:

            .../conf/server.xml

    setting the reloadable attribute of the Default Context element to "true", as:

            <DefaultContext reloadable="true"/>

    --Fred

  4. Auto-Reloading Webapps More Often

    Last Updated: 1/7/2006
    Applies to: Tomcat 5.0.28+

    To cause Tomcat to more frequently (every 10 seconds in this case) check for and load code for a Webapp, add a <Loader> element to the <Context> element of the context configuration file, as:

            <Context  docBase="/home/fred/bristle/webapps/mywebapp/web" 
                            path="/mywebapp"
                            reloadable="true">
                <Loader checkInterval="10" />
            </Context>

    You may not want to do this for a production server, since it wastes unnecessary CPU cycles in an environment where files do not change often, but it's very handy on a development server.

    --Fred

©Copyright 2006-2008, Bristle Software, Inc.  All rights reserved