Skip to content

Instantly share code, notes, and snippets.

@slevine
Forked from ae6rt/gist:3697746
Last active May 16, 2016 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slevine/4569483 to your computer and use it in GitHub Desktop.
Save slevine/4569483 to your computer and use it in GitHub Desktop.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment