blob: 2145743f3a14f6739740a2b3b10a27609653b0c0 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 (6.0.39) - Tomcat Web Application Deployment</title><meta name="author" content="Allistair Crossley"><style type="text/css" media="print">
2 .noPrint {display: none;}
3 td#mainBody {width: 100%;}
4 </style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
5 The Apache Tomcat Servlet/JSP Container
6 " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 6.0</font></h1><font face="arial,helvetica,sanserif">Version 6.0.39, Jan 27 2014</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.gif" align="right" alt="Apache Logo" border="0"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade="noshade" size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap="nowrap" class="noPrint"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptor-howto.html">16) MBean Descriptor</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Apache Tomcat 6.0</h1><h2>Tomcat Web Application Deployment</h2><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
7<ul><li><a href="#Introduction">Introduction</a></li><li><a href="#Installation">Installation</a></li><li><a href="#A_word_on_Contexts">A word on Contexts</a></li><li><a href="#Deployment_on_Tomcat_startup">Deployment on Tomcat startup</a></li><li><a href="#Deploying_on_a_running_Tomcat_server">Deploying on a running Tomcat server</a></li><li><a href="#Deploying_using_the_Tomcat_Manager">Deploying using the Tomcat Manager</a></li><li><a href="#Deploying_using_the_Client_Deployer_Package">Deploying using the Client Deployer Package</a></li></ul>
8</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
9 <p>
10 Deployment is the term used for the process of installing a web
11 application (either a 3rd party WAR or your own custom web application)
12 into the Tomcat server.
13 </p>
14 <p>
15 Web application deployment may be accomplished in a number of ways
16 within the Tomcat server.</p>
17 <ul>
18 <li>Statically; the web application is setup before Tomcat is started</li>
19 <li>
20 Dynamically; by directly manipulating already deployed web
21 applications (relying on <em>auto-deployment</em>
22 feature) or remotely by using the Tomcat Manager web
23 application
24 </li>
25 </ul>
26 <p>
27 The <a href="manager-howto.html">Tomcat Manager</a> is a web
28 application that can be used interactively (via HTML GUI) or
29 programmatically (via URL-based API) to deploy and manage web
30 applications.
31 </p>
32 <p>
33 There are a number of ways to perform deployment that rely on
34 the Manager web application. Apache Tomcat provides tasks
35 for Apache Ant build tool.
36 <a href="http://tomcat.apache.org/">Apache Tomcat Maven Plugin</a>
37 project provides integration with Apache Maven.
38 There is also a tool called the Client Deployer, which can be
39 used from a command line and provides additional functionality
40 such as compiling and validating web applications as well as
41 packaging web application into web application resource (WAR)
42 files.
43 </p>
44 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Installation"><strong>Installation</strong></a></font></td></tr><tr><td><blockquote>
45 <p>
46 There is no installation required for static deployment of web
47 applications as this is provided out of the box by Tomcat. Nor is any
48 installation required for deployment functions with the Tomcat Manager,
49 although some configuration is required as detailed in the
50 <a href="manager-howto.html">Tomcat Manager manual</a>.
51 An installation is however required if you wish
52 to use the Tomcat Client Deployer (TCD).
53 </p>
54 <p>
55 The TCD is not packaged with the Tomcat core
56 distribution, and must therefore be downloaded separately from
57 the Downloads area. The download is usually labelled
58 <i>apache-tomcat-6.0.x-deployer</i>.
59 </p>
60 <p>
61 TCD has prerequisites of Apache Ant 1.6.2+ and a Java installation.
62 Your environment should define an ANT_HOME environment value pointing to
63 the root of your Ant installation, and a JAVA_HOME value pointing to
64 your Java installation. Additionally, you should ensure Ant's ant
65 command, and the Java javac compiler command run from the command shell
66 that your operating system provides.
67 </p>
68 <ol>
69 <li>Download the TCD distribution</li>
70 <li>
71 The TCD package need not be extracted into any existing Tomcat
72 installation, it can be extracted to any location.
73 </li>
74 <li>Read Using the <a href="#Deploying using the Client Deployer Package">
75 Tomcat Client Deployer</a></li>
76 </ol>
77 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="A word on Contexts"><!--()--></a><a name="A_word_on_Contexts"><strong>A word on Contexts</strong></a></font></td></tr><tr><td><blockquote>
78 <p>
79 In talking about deployment of web applications, the concept of a
80 <i>Context</i> is required to be understood. A Context is what Tomcat
81 calls a web application.
82 </p>
83 <p>
84 In order to configure a Context within Tomcat a <i>Context Descriptor</i>
85 is required. A Context Descriptor is simply an XML file that contains
86 Tomcat related configuration for a Context, e.g naming resources or
87 session manager configuration. In earlier versions of
88 Tomcat the content of a Context Descriptor configuration was often stored within
89 Tomcat's primary configuration file <i>server.xml</i> but this is now
90 discouraged (although it currently still works).
91 </p>
92 <p>
93 Context Descriptors not only help Tomcat to know how to configure
94 Contexts but other tools such as the Tomcat Manager and TCD often use
95 these Context Descriptors to perform their roles properly.
96 </p>
97 <p>
98 The locations for Context Descriptors are:
99 </p>
100 <ol>
101 <li>$CATALINA_BASE/conf/[enginename]/[hostname]/[webappname].xml</li>
102 <li>$CATALINA_BASE/webapps/[webappname]/META-INF/context.xml</li>
103 </ol>
104 <p>
105 Files in (1) are named [webappname].xml but files in (2) are named
106 context.xml. If a Context Descriptor is not provided for a Context,
107 Tomcat configures the Context using default values.
108 </p>
109 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Deployment on Tomcat startup"><!--()--></a><a name="Deployment_on_Tomcat_startup"><strong>Deployment on Tomcat startup</strong></a></font></td></tr><tr><td><blockquote>
110 <p>
111 If you are not interested in using the Tomcat Manager, or TCD,
112 then you'll need to deploy your web applications
113 statically to Tomcat, followed by a Tomcat startup. The location you
114 deploy web applications to for this type of deployment is called the
115 <code>appBase</code> which is specified per Host. You either copy a
116 so-called <i>exploded web application</i>, i.e non-compressed, to this
117 location, or a compressed web application resource .WAR file.
118 </p>
119 <p>
120 The web applications present in the location specified by the Host's
121 (default Host is "localhost") <code>appBase</code> attribute (default
122 appBase is "$CATALINA_BASE/webapps") will be deployed on Tomcat startup
123 only if the Host's <code>deployOnStartup</code> attribute is "true".
124 </p>
125 <p>
126 The following deployment sequence will occur on Tomcat startup in that
127 case:
128 </p>
129 <ol>
130 <li>Any Context Descriptors will be deployed first.</li>
131 <li>
132 Exploded web applications not referenced by any Context
133 Descriptor will then be deployed. If they have an associated
134 .WAR file in the appBase and it is newer than the exploded web application,
135 the exploded directory will be removed and the webapp will be
136 redeployed from the .WAR
137 </li>
138 <li>.WAR files will be deployed</li>
139 </ol>
140 <p>
141 Note again that for each deployed web application, a
142 Context Descriptor will be created <i>unless one exists already</i>.
143 </p>
144 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Deploying on a running Tomcat server"><!--()--></a><a name="Deploying_on_a_running_Tomcat_server"><strong>Deploying on a running Tomcat server</strong></a></font></td></tr><tr><td><blockquote>
145 <p>
146 It is possible to deploy web applications to a running Tomcat server.
147 </p>
148 <p>
149 If the Host <code>autoDeploy</code> attribute is "true", the Host will
150 attempt to deploy and update web applications dynamically, as needed,
151 for example if a new .WAR is dropped into the <code>appBase</code>.
152 For this to work, the Host needs to have background processing
153 enabled which is the default configuration.
154 </p>
155
156 <p>
157 <code>autoDeploy</code> set to "true" and a running Tomcat allows for:
158 </p>
159 <ul>
160 <li>Deployment of .WAR files copied into the Host <code>appBase</code>.</li>
161 <li>
162 Deployment of exploded web applications which are
163 copied into the Host <code>appBase</code>.
164 </li>
165 <li>
166 Re-deployment of a web application which has already been deployed from
167 a .WAR when the new .WAR is provided. In this case the exploded
168 web application is removed, and the .WAR is expanded again.
169 Note that the explosion will not occur if the Host is configured
170 so that .WARs are not exploded with a <code>unpackWARs</code>
171 attribute set to "false", in which case the web application
172 will be simply redeployed as a compressed archive.
173 </li>
174 <li>
175 Re-deployment of a web application if the /WEB-INF/web.xml file (or any
176 other resource defined as a WatchedResource) is updated.
177 </li>
178 <li>
179 Re-deployment of a web application if the Context Descriptor file from which
180 the web application has been deployed is updated.
181 </li>
182 <li>
183 Re-deployment of a web application if a Context Descriptor file (with a
184 filename corresponding to the Context path of the previously deployed
185 web application) is added to the
186 <code>$CATALINA_BASE/conf/[enginename]/[hostname]/</code>
187 directory.
188 </li>
189 <li>
190 Undeployment of a web application if its document base (docBase)
191 is deleted. Note that on Windows, this assumes that anti-locking
192 features (see Context configuration) are enabled, otherwise it is not
193 possible to delete the resources of a running web application.
194 </li>
195 </ul>
196 <p>
197 Note that web application reloading can also be configured in the loader, in which
198 case loaded classes will be tracked for changes.
199 </p>
200 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Deploying using the Tomcat Manager"><!--()--></a><a name="Deploying_using_the_Tomcat_Manager"><strong>Deploying using the Tomcat Manager</strong></a></font></td></tr><tr><td><blockquote>
201 <p>
202 The Tomcat Manager is covered in its <a href="manager-howto.html">own manual page</a>.
203 </p>
204 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Deploying using the Client Deployer Package"><!--()--></a><a name="Deploying_using_the_Client_Deployer_Package"><strong>Deploying using the Client Deployer Package</strong></a></font></td></tr><tr><td><blockquote>
205 <p>
206 Finally, deployment of web application may be achieved using the
207 Tomcat Client Deployer. This is a package which can be used to
208 validate, compile, compress to .WAR, and deploy web applications to
209 production or development Tomcat servers. It should be noted that this feature
210 uses the Tomcat Manager and as such the target Tomcat server should be
211 running.
212 </p>
213
214 <p>
215 It is assumed the user will be familiar with Apache Ant for using the TCD.
216 Apache Ant is a scripted build tool. The TCD comes pre-packaged with a
217 build script to use. Only a modest understanding of Apache Ant is
218 required (installation as listed earlier in this page, and familiarity
219 with using the operating system command shell and configuring
220 environment variables).
221 </p>
222
223 <p>
224 The TCD includes Ant tasks, the Jasper page compiler for JSP compilation
225 before deployment, as well as a task which
226 validates the web application Context Descriptor. The validator task (class
227 <code>org.apache.catalina.ant.ValidatorTask</code>) allows only one parameter:
228 the base path of an exploded web application.
229 </p>
230
231 <p>
232 The TCD uses an exploded web application as input (see the list of the
233 properties used below). A web application that is programmatically
234 deployed with the deployer may include a Context Descriptor in
235 <code>/META-INF/context.xml</code>.
236 </p>
237
238 <p>
239 The TCD includes a ready-to-use Ant script, with the following targets:
240 </p>
241 <ul>
242 <li>
243 <code>compile</code> (default): Compile and validate the web
244 application. This can be used standalone, and does not need a running
245 Tomcat server. The compiled application will only run on the associated
246 Tomcat 6.0.x server release, and is not guaranteed to work on another
247 Tomcat release, as the code generated by Jasper depends on its runtime
248 component. It should also be noted that this target will also compile
249 automatically any Java source file located in the
250 <code>/WEB-INF/classes</code> folder of the web application.</li>
251 <li>
252 <code>deploy</code>: Deploy a web application (compiled or not) to
253 a Tomcat server.
254 </li>
255 <li><code>undeploy</code>: Undeploy a web application</li>
256 <li><code>start</code>: Start web application</li>
257 <li><code>reload</code>: Reload web application</li>
258 <li><code>stop</code>: Stop web application</li>
259 </ul>
260
261 <p>
262 In order for the deployment to be configured, create a file
263 called <code>deployer.properties</code> in the TCD installation
264 directory root. In this file, add the following name=value pairs per
265 line:
266 </p>
267
268 <p>
269 Additionally, you will need to ensure that a user has been
270 setup for the target Tomcat Manager (which TCD uses) otherwise the TCD
271 will not authenticate with the Tomcat Manager and the deployment will
272 fail. To do this, see the Tomcat Manager page.
273 </p>
274
275 <ul>
276 <li>
277 <code>build</code>: The build folder used will be, by default,
278 <code>${build}/webapp/${path}</code>. After the end of the execution
279 of the <code>compile</code> target, the web application .WAR will be
280 located at <code>${build}/webapp/${path}.war</code>.
281 </li>
282 <li>
283 <code>webapp</code>: The directory containing the exploded web application
284 which will be compiled and validated. By default, the folder is
285 <code>myapp</code>.
286 </li>
287 <li>
288 <code>path</code>: Deployed context path of the web application,
289 by default <code>/myapp</code>.
290 </li>
291 <li>
292 <code>url</code>: Absolute URL to the Tomcat Manager web application of a
293 running Tomcat server, which will be used to deploy and undeploy the
294 web application. By default, the deployer will attempt to access
295 a Tomcat instance running on localhost, at
296 <code>http://localhost:8080/manager</code>.
297 </li>
298 <li>
299 <code>username</code>: Tomcat Manager username (user should have a role of
300 manager-script)
301 </li>
302 <li><code>password</code>: Tomcat Manager password.</li>
303 </ul>
304 </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade="noshade" size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
305 Copyright &copy; 1999-2014, Apache Software Foundation
306 </em></font></div></td></tr></table></body></html>