Tomcat autodeploy: war or exploded web application 

Joined:
04/09/2007
Posts:
776

February 14, 2010 23:00:53    Last update: February 16, 2010 03:20:24
Tomcat auto-deploys WAR files or exploded web applications copied to the appBase directory by default. The default Host configuration in server.xml looks like this:
<!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">


So the appBase directory is named webapps by default, which is where the manager and examples applications are. You can deploy a new application by dropping your WAR file, or copying your application in exploded WAR structure to the same directory.

Your application is automatically re-deployed when a new WAR file is copied to webapps, or, in exploded structure, WEB-INF/web.xml is updated. The reason that Tomcat knows to reload a web application when web.xml is updated is because of the WatchedResource declaration in $CATALINA_BASE/conf/context.xml:
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->

</Context>


It is possible to configure the Loader element to watch all class files in your web application and re-deploy the application when any class is updated. But that incurs significant overhead for any non-trivial application. It's probably far better to drop a new WAR, or simply touch WEB-INF/web.xml.

Please also note that redeployment may fail when you are copying a WAR file at the same time Tomcat is checking for updates - Tomcat seems not to know that the WAR is currently being copied.
Share |
| Comment  | Tags