There are four different ways one can deploy a webapp to Tomcat.
If $TOMCAT_HOME
is the Tomcat top-level directory:
- Copy the war file foo.war or exploded war directory to
$TOMCAT_HOME/webapps
- Create a context file context.xml in the webapp’s META-INF/ directory that contains a fragment that describes the webapp deployment
- Add a
<Context>
element to the<Host>
element in Tomcat’s server.xml that describes the webapp deployment, including docBase. docBase is a attribute that locates the war file or exploded war directory in the filesystem. - Create a context file foo.xml in
$TOMCAT_HOME/conf/Catalina/localhost/foo.xml
that contains a fragment that describes the webapp deployment, including docBase.
Sample $TOMCAT_HOME/conf/Catalina/localhost/foo.xml
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="~/projects/foo/target/foo-0.1-SNAPSHOT.war"
path="/foo"
reloadable="true">
</Context>
The first two methods do not provide the freedom to name the servlet context independent of file system names for the war file or exploded war directory, whereas the last two do. Of the two methods that provide control over context naming, the most appealing is the use of a context file foo.xml placed in TOMCAT_HOME/conf/Catalina/localhost/foo.xml
, as it avoids modifying the stock server.xml file for pure context deployment purposes. For the root context “/”, the context file name is ROOT.xml.