O'Reilly logo

Tomcat: The Definitive Guide, 2nd Edition by Ian F. Darwin, Jason Brittain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Deploying a WAR File

Another major way of deploying a web application into Tomcat is to deploy the application packed into a WAR file. WAR files are described in detail in the Java Servlet Specification.

With Tomcat, when you deploy your WAR file, you must decide whether to serve your webapp after unpacking the WAR file or while it is still packed into a WAR file. Both ways are supported. By default, when Tomcat deploys a WAR file, the first thing it does is unpack the contents of the WAR file into a directory of the same name minus the .war extension, and then serves the files from the unpacked directory.

For example, if your WAR file is named suitcase.war, Tomcat would unpack the contents of suitcase.war into a directory named suitcase, and then the files that are served as part of the webapp will be read from the suitcase directory on disk, not from the WAR file. You may turn off the automatic unpacking behavior by setting unpackWARs="false" on your Host element in server.xml. With it set to false, Tomcat will serve your webapp's files right from the packed WAR file itself.

There are two ways to configure Tomcat to recognize and start your web application when you first deploy it as a WAR file:

server.xml context deployment

Add a <Context> element to the server.xml file and restart Tomcat.

Context XML fragment file deployment

Add a new context XML fragment file in Tomcat's CATALINA_HOME/conf/[EngineName]/[Hostname] directory tree, or create it as your web application's WEB-INF/context.xml ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required