Skip to Content
Tomcat: The Definitive Guide, 2nd Edition
book

Tomcat: The Definitive Guide, 2nd Edition

by Jason Brittain, Ian F. Darwin
October 2007
Intermediate to advanced
496 pages
16h 50m
English
O'Reilly Media, Inc.
Content preview from Tomcat: The Definitive Guide, 2nd Edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Servlets and JSP, 2nd Edition

Head First Servlets and JSP, 2nd Edition

Bryan Basham, Kathy Sierra, Bert Bates
Kubernetes: Up and Running, 2nd Edition

Kubernetes: Up and Running, 2nd Edition

Brendan Burns, Joe Beda, Kelsey Hightower
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9780596101060Supplemental ContentErrata