radioAe6rt

The four ways to deploy a webapp under Tomcat

with one comment

There are four different ways one can deploy a webapp to Tomcat.  If TCHOME is the Tomcat top-level directory:

  • Copy the war file foo.war or exploded war directory to TCHOME/webapps
  • Create a context file context.xml in the webapp’s META-INF/ directory that contains a <Context> 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 <Context> attribute that locates the war file or exploded war directory in the filesystem.
  • Create a context file foo.xml in TCHOME/conf/Catalina/localhost/foo.xml that contains a <Context> fragment that describes the webapp deployment, including docBase.

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 TCHOME/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.

Advertisement

Written by radioae6rt

June 22, 2011 at 6:50 pm

Posted in Uncategorized

One Response

Subscribe to comments with RSS.

  1. A word to the wise — when doing step 1 (the easiest of the 4 imho), never copy the war file across the network or disks. Tomcat may try to deploy it before the entire file is copied, resulting in an internal exception being thrown and tomcat marking the war file as invalid. But in this case, you can always remove the warfile, restart tomcat, and redeploy to force it into loading the war.

    Nik Reiman

    June 23, 2011 at 2:48 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.