Lines 8-180
Link Here
|
8 |
|
8 |
|
9 |
<properties> |
9 |
<properties> |
10 |
<author email="remm@apache.org">Remy Maucherat</author> |
10 |
<author email="remm@apache.org">Remy Maucherat</author> |
11 |
<title>Deployer HOW-TO</title> |
11 |
<title>Tomcat Web Application Deployment</title> |
12 |
</properties> |
12 |
</properties> |
13 |
|
13 |
|
14 |
<body> |
14 |
<body> |
15 |
|
15 |
|
16 |
<section name="Table of Contents"> |
16 |
<section name="Table of Contents"> |
17 |
|
17 |
<ul> |
18 |
<p> |
18 |
<li><a href="#Introduction">Introduction</a></li> |
19 |
<a href="#Introduction">Introduction</a><br /> |
19 |
<li><a href="#Installation">Installation</a></li> |
20 |
<a href="#Context descriptors">Context XML descriptors</a><br /> |
20 |
<li><a href="#A word on Contexts">A word on Contexts</a></li> |
21 |
<a href="#Deploying on Tomcat startup">Deploying on Tomcat startup</a><br /> |
21 |
<li><a href="#Deployment on Tomcat startup">Deployment on Tomcat startup</a></li> |
22 |
<a href="#Deploying on a running Tomcat server">Deploying on running Tomcat server</a><br /> |
22 |
<li><a href="#Deploying on a running Tomcat server">Deploying on a running Tomcat server</a></li> |
23 |
<a href="#Deploying using the Client Deployer Package">Deploying using the Client Deployer Package</a><br /> |
23 |
<li><a href="#Deploying using the Tomcat Manager">Deploying using the Tomcat Manager</a></li> |
24 |
<blockquote> |
24 |
<li><a href="#Deploying using the Client Deployer Package">Deploying using |
25 |
</blockquote> |
25 |
the Tomcat Client Deployer</a></li> |
26 |
</p> |
26 |
</ul> |
27 |
|
27 |
|
28 |
</section> |
28 |
</section> |
29 |
|
29 |
|
30 |
<section name="Introduction"> |
30 |
<section name="Introduction"> |
31 |
|
31 |
<p> |
32 |
<p>The deployer, as its name implies, allows deploying and undeploying web |
32 |
Deployment is the term used for the process of installing a web |
33 |
applications to the Tomcat server, either statically (the application is |
33 |
application (either a 3rd party WAR or your own custom web application) |
34 |
setup before the server is started), or dynamically (in conjunction with the |
34 |
into the Tomcat server. |
35 |
Tomcat Manager web application or manipulating already deployed applications). |
35 |
</p> |
36 |
</p> |
36 |
<p> |
37 |
|
37 |
Web application deployment may be accomplished in a number of ways |
38 |
</section> |
38 |
within the Tomcat server. |
39 |
|
39 |
<ul> |
40 |
<section name="Context descriptors"> |
40 |
<li>Statically; the web application is setup before Tomcat is started</li> |
41 |
|
41 |
<li> |
42 |
<p>A Context XML descriptor is a fragment of XML data which contains a valid |
42 |
Dynamically; in conjunction with the Tomcat Manager web application or |
43 |
Context element which would normally be found in the main server configuration |
43 |
manipulating already deployed web applications |
44 |
file (conf/server.xml), and allows easy and automated manipulation |
44 |
</li> |
45 |
of web applications by the various management tools available in Tomcat. |
45 |
</ul> |
46 |
For a given host, the Context descriptors are located in |
46 |
</p> |
47 |
<code>$CATALINA_HOME/conf/[enginename]/[hostname]/foo.xml</code>. Note that |
47 |
<p> |
48 |
while the name of the file is not tied to the webapp name, Tomcat will create |
48 |
The Tomcat Manager is a tool that allows URL-based web application |
49 |
Context descriptors which match the webapp name whenever it will generate a |
49 |
deployment features. There is also a tool called the Client Deployer, |
50 |
Context descriptor. |
50 |
which is a command shell based script that interacts with the Tomcat |
51 |
</p> |
51 |
Manager but provides additional functionality such as compiling and |
52 |
|
52 |
validating web applications as well as packaging web application into |
53 |
<p>Context descriptors allow defining all aspects and configuration parameters |
53 |
web application resource (WAR) files. |
54 |
of a Context, such as naming resources and session manager configuration. |
54 |
</p> |
55 |
It should be noted that the docBase specified in the Context element can |
55 |
</section> |
56 |
refer to either the .WAR or the directory which will be created when the |
56 |
|
57 |
.WAR is expanded or the .WAR itself.</p> |
57 |
<section name="Installation"> |
58 |
|
58 |
<p> |
59 |
</section> |
59 |
There is no installation required for static deployment of web |
60 |
|
60 |
applications as this is provided out of the box by Tomcat. Nor is any |
61 |
<section name="Deploying on Tomcat startup"> |
61 |
installation required for deployment functions with the Tomcat Manager, |
62 |
|
62 |
although some configuration is required as detailed in the |
63 |
<p>The webapps which are present in the host appBase will be deployed if the |
63 |
Tomcat Manager manual. An installation is however required if you wish |
64 |
host "deployOnStartup" property is true. The deployment process is |
64 |
to use the Tomcat Client Deployer (TCD). |
65 |
the following: |
65 |
</p> |
66 |
<ul> |
66 |
<p> |
67 |
<li>The Context XML declarations will be deployed first</li> |
67 |
The TCD is not packaged with the Tomcat core |
68 |
<li>Expanded web applications not referenced by Context XML declarations |
68 |
distribution, and must therefore be downloaded separately from |
69 |
will then be deployed; if they have an associated .WAR file and it is |
69 |
the Downloads area. The download is usually labelled |
70 |
newer than the expanded web application, the expanded directory will |
70 |
<i>jakarta-tomcat-5.5.x-deployer</i>. |
71 |
be removed and the webapp will be redeployed from the .WAR</li> |
71 |
</p> |
72 |
<li>.WAR files will be deployed</li> |
72 |
<p> |
73 |
</ul> |
73 |
TCD has prerequisites of Apache Ant 1.6.2+ and a Java installation. |
74 |
For each deployed web application, a matching Context XML descriptor will be |
74 |
Your environment should define an ANT_HOME environment value pointing to |
75 |
created unless one exists already. |
75 |
the root of your Ant installation, and a JAVA_HOME value pointing to |
76 |
</p> |
76 |
your Java installation. Additionally, you should ensure Ant's ant |
77 |
|
77 |
command, and the Java javac compiler command run from the command shell |
78 |
</section> |
78 |
that your operating system provides. |
79 |
|
79 |
</p> |
80 |
<section name="Deploying on a running Tomcat server"> |
80 |
<ol> |
81 |
|
81 |
<li>Download the TCD distribution</li> |
82 |
<p>If the host "autoDeploy" property is true, the host will attempt to deploy |
82 |
<li> |
83 |
and update web applications dynamically, as needed. The host will need to |
83 |
The TCD package need not be extracted into any existing Tomcat |
84 |
have background processing enabled for automatic reloading to work, which |
84 |
installation, it can be extracted to any location. |
85 |
is the default.</p> |
85 |
</li> |
86 |
|
86 |
<li>Read Using the <a href="tdc">Tomcat Client Deployer</a></li> |
87 |
<p>This includes: |
87 |
</ol> |
88 |
<ul> |
88 |
</section> |
89 |
<li>Deployment of WARs which are copied to the host appBase.</li> |
89 |
|
90 |
<li>Deployment of expanded web applications which are copied to the host |
90 |
<section name="A word on Contexts"> |
91 |
appBase.</li> |
91 |
<p> |
92 |
<li>Redeployment of a web application which has been deployed from a WAR |
92 |
In talking about deployment of web applications, the concept of a |
93 |
when the WAR is updated: the expanded web application is removed, |
93 |
<i>Context</i> is required to be understood. A Context is what Tomcat |
94 |
and the WAR is expanded again. This will not happen if the host is |
94 |
calls a web application. |
95 |
configured so that WARs are not expanded, in which case the webapp |
95 |
</p> |
96 |
will be simply redeployed.</li> |
96 |
<p> |
97 |
<li>Redeployment of the web application if the /WEB-INF/web.xml file is |
97 |
In order to configure a Context within Tomcat a <i>Context Descriptor</i> |
98 |
updated.</li> |
98 |
is required. A Context Descriptor is simply an XML file that contains |
99 |
<li>Redeployment of the web application if the context XML file from which |
99 |
Tomcat related configuration for a Context, e.g naming resources or |
100 |
the web application has been deployed is updated.</li> |
100 |
session manager configuration. In earlier versions of |
101 |
<li>Redeployment of the web application if a context XML file (with a |
101 |
Tomcat the content of a Context Descriptor configuration was often stored within |
102 |
name corresponding to the context path of the previously deployed |
102 |
Tomcat's primary configuration file <i>server.xml</i> but this is now |
103 |
application) is added in the |
103 |
discouraged (although it currently still works). |
104 |
<code>$CATALINA_HOME/conf/[enginename]/[hostname]/</code> folder.</li> |
104 |
</p> |
105 |
<li>Undeployment of the web application if its document base is deleted |
105 |
<p> |
106 |
(on Windows, this assumes that anti locking features are enabled, otherwise |
106 |
Context Descriptors not only help Tomcat to know how to configure |
107 |
it is not possible to delete the resources of a running web application).</li> |
107 |
Contexts but other tools such as the Tomcat Manager and TDC often use |
108 |
</ul> |
108 |
these Context Descriptors to perform their roles properly. |
109 |
Note: Web application reloading can also be configured in the loader, in which |
109 |
</p> |
110 |
case loaded classes will be tracked for changes. |
110 |
<p> |
111 |
</p> |
111 |
The locations for Context Descriptors are; |
112 |
|
112 |
<ol> |
113 |
</section> |
113 |
<li>$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml</li> |
114 |
|
114 |
<li>$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml</li> |
115 |
<section name="Deploying using the Client Deployer Package"> |
115 |
</ol> |
116 |
|
116 |
If a Context Descriptor is not provided for a Context, Tomcat |
117 |
<p>The client deployer is a package which can be used to validate, compile, |
117 |
automatically creates one and places it in (1) with a filename of |
118 |
and deploy a web application to a production or development server. It should |
118 |
[webappname].xml although if manually created, the filename need not |
119 |
be noted that this feature uses the Tomcat manager for automatic deployment. |
119 |
match the web application name as Tomcat is concerned only with the |
120 |
</p> |
120 |
Context configuration contained within the Context Descriptor file(s). |
121 |
|
121 |
</p> |
122 |
<p>The deployer includes the Catalina manager Ant tasks, the Jasper page |
122 |
</section> |
123 |
compiler for JSP compilation before deployment, as well as a task which |
123 |
|
124 |
validates the webapp's deployment descriptor. The validator task (class |
124 |
<section name="Deployment on Tomcat startup"> |
125 |
<code>org.apache.catalina.ant.ValidatorTask</code>) allows only one parameter: |
125 |
<p> |
126 |
the base path of an expanded web application.</p> |
126 |
If you are not interested in using the Tomcat Manager, or TCD, |
127 |
|
127 |
then you'll need to deploy your web applications |
128 |
<p>The deployer uses an unpacked web application as input (see the list of the |
128 |
statically to Tomcat, followed by a Tomcat startup. The location you |
129 |
properties used by the deployer below). A web application which |
129 |
deploy web applications to for this type of deployment is called the |
130 |
is programatically deployed with the deployer may include Tomcat specific |
130 |
<code>appBase</code> which is specified per Host. You either copy a |
131 |
deployment configuration, by including a Context configuration XML file in |
131 |
so-called <i>exploded web application</i>, i.e non-compressed, to this |
132 |
<code>/META-INF/context.xml</code>.</p> |
132 |
location, or a compressed web application resource .WAR file. |
133 |
|
133 |
</p> |
134 |
<p>The deployer package includes a ready to use Ant script, with the following |
134 |
<p> |
135 |
targets: |
135 |
The web applications present in the location specified by the Host's |
136 |
<ul> |
136 |
(default Host is "localhost") <code>appBase</code> attribute (default |
137 |
<li><code>compile</code> (default): Compile and validate the web |
137 |
appBase is "$CATALINA_HOME/webapps") will be deployed on Tomcat startup |
138 |
application. This can be used standalone, and does not need a running |
138 |
only if the Host's <code>deployOnStartup</code> attribute is "true". |
139 |
Tomcat server. The compiled application will only run on the associated |
139 |
</p> |
140 |
Tomcat 5.5.x server release, and is not guaranteed to work on another |
140 |
<p> |
141 |
Tomcat release, as the code generated by Jasper depends on its runtime |
141 |
The following deployment sequence will occur on Tomcat startup in that |
142 |
component. It should also be noted that this target will also compile |
142 |
case: |
143 |
automatically any Java source file located in the |
143 |
</p> |
144 |
<code>/WEB-INF/classes</code> folder of the web application.</li> |
144 |
<ol> |
145 |
<li><code>deploy</code>: Deploy a web application (compiled or not) to |
145 |
<li>Any Context Descriptors will be deployed first.</li> |
146 |
a Tomcat server</li> |
146 |
<li> |
147 |
<li><code>undeploy</code>: Undeploy a web application</li> |
147 |
Exploded web applications not referenced by any Context |
148 |
<li><code>start</code>: Start web application</li> |
148 |
Descriptor will then be deployed. If they have an associated |
149 |
<li><code>reload</code>: Reload web application</li> |
149 |
.WAR file in the appBase and it is newer than the exploded web application, |
150 |
<li><code>stop</code>: Stop web application</li> |
150 |
the exploded directory will be removed and the webapp will be |
151 |
</ul> |
151 |
redeployed from the .WAR |
152 |
The following properties can be specified, either as system properties, or by |
152 |
</li> |
153 |
using a <code>deployer.properties</code> file located in the root folder of the |
153 |
<li>.WAR files will be deployed</li> |
154 |
deployer package: |
154 |
</ol> |
155 |
<ul> |
155 |
<p> |
156 |
<li><code>build</code>: The build folder used will be, by default, |
156 |
Note again that for each deployed web application, a |
157 |
<code>${build}/webapp${path}</code>. After the end of the execution |
157 |
Context Descriptor will be created <i>unless one exists already</i>. |
158 |
of the <code>compile</code> target, the web application WAR will be |
158 |
</p> |
159 |
located at <code>${build}/webapp${path}.war</code>.</li> |
159 |
</section> |
160 |
<li><code>webapp</code>: Folder containing the expanded web application |
160 |
|
161 |
which will be compiled and validated. By default, the folder is |
161 |
<section name="Deploying on a running Tomcat server"> |
162 |
<code>myapp</code>.</li> |
162 |
<p> |
163 |
<li><code>path</code>: Deployed context path of the web application, |
163 |
It is possible to deploy web applications to a running Tomcat server. |
164 |
by default <code>/myapp</code>.</li> |
164 |
</p> |
165 |
<li><code>url</code>: Absolute URL to the manager web application of a |
165 |
<p> |
166 |
running Tomcat server, which will be used to deploy and undeploy the |
166 |
If the Host <code>autoDeploy</code> attribute is "true", the Host will |
167 |
web application. By default, the deployer will attempt to access |
167 |
attempt to deploy and update web applications dynamically, as needed, |
168 |
a Tomcat instance running on localhost, at |
168 |
for example if a new .WAR is dropped into the <code>appBase</code>. |
169 |
<code>http://localhost:8080/manager</code>.</li> |
169 |
For this to work, the Host needs to have background processing |
170 |
<li><code>username</code>: Username to be used to connect to the Tomcat |
170 |
enabled which is the default configuration. |
171 |
manager.</li> |
171 |
</p> |
172 |
<li><code>password</code>: Password to be used to connect to the Tomcat |
172 |
|
173 |
manager.</li> |
173 |
<p> |
174 |
</ul> |
174 |
<code>autoDeploy</code> set to "true" and a running Tomcat allows for: |
175 |
</p> |
175 |
</p> |
176 |
|
176 |
<ul> |
177 |
</section> |
177 |
<li>Deployment of .WAR files copied into the Host <code>appBase</code>.</li> |
|
|
178 |
<li> |
179 |
Deployment of exploded web applications which are |
180 |
copied into the Host <code>appBase</code>. |
181 |
</li> |
182 |
<li> |
183 |
Re-deployment of a web application which has already been deployed from |
184 |
a .WAR when the new .WAR is provided. In this case the exploded |
185 |
web application is removed, and the .WAR is expanded again. |
186 |
Note that the explosion will not occur if the Host is configured |
187 |
so that .WARs are not exploded with a <code>unpackWARs</code> |
188 |
attribute set to "false", in which case the web application |
189 |
will be simply redeployed as a compressed archive. |
190 |
</li> |
191 |
<li> |
192 |
Re-deployment of a web application if the /WEB-INF/web.xml file is |
193 |
updated. |
194 |
</li> |
195 |
<li> |
196 |
Re-deployment of a web application if the Context Descriptor file from which |
197 |
the web application has been deployed is updated. |
198 |
</li> |
199 |
<li> |
200 |
Re-deployment of a web application if a Context Descriptor file (with a |
201 |
filename corresponding to the Context path of the previously deployed |
202 |
web application) is added to the |
203 |
<code>$CATALINA_HOME/conf/[enginename]/[hostname]/</code> |
204 |
directory. |
205 |
</li> |
206 |
<li> |
207 |
Undeployment of a web application if its document base (docBase) |
208 |
is deleted. Note that on Windows, this assumes that anti-locking |
209 |
features (see Context configuration) are enabled, otherwise it is not |
210 |
possible to delete the resources of a running web application). |
211 |
</li> |
212 |
</ul> |
213 |
<p> |
214 |
Note that web application reloading can also be configured in the loader, in which |
215 |
case loaded classes will be tracked for changes. |
216 |
</p> |
217 |
</section> |
218 |
|
219 |
<section name="Deploying using the Tomcat Manager"> |
220 |
<p> |
221 |
The Tomcat Manager is covered in its <a href="manager-howto.html">own manual page</a>. |
222 |
</p> |
223 |
</section> |
224 |
|
225 |
<section name="Deploying using the Client Deployer Package"> |
226 |
<p> |
227 |
Finally, deployment of web application may be achieved using the |
228 |
Tomcat Client Deployer. This is a package which can be used to |
229 |
validate, compile, compress to .WAR, and deploy web applications to |
230 |
production or development Tomcat servers. It should be noted that this feature |
231 |
uses the Tomcat Manager and as such the target Tomcat server should be |
232 |
running. |
233 |
</p> |
234 |
|
235 |
<p> |
236 |
It is assumed the user will be familar with Apache Ant for using the TCD. |
237 |
Apache Ant is a scripted build tool. The TCD comes pre-packaged with a |
238 |
build script to use. Only a modest understanding of Apache Ant is |
239 |
required (installation as listed earlier in this page, and familiarity |
240 |
with using the operating system command shell and configuring |
241 |
environment variables). |
242 |
</p> |
243 |
|
244 |
<p> |
245 |
The TCD includes Ant tasks, the Jasper page compiler for JSP compilation |
246 |
before deployment, as well as a task which |
247 |
validates the web application Context Descriptor. The validator task (class |
248 |
<code>org.apache.catalina.ant.ValidatorTask</code>) allows only one parameter: |
249 |
the base path of an exploded web application. |
250 |
</p> |
251 |
|
252 |
<p> |
253 |
The TCD uses an exploded web application as input (see the list of the |
254 |
properties used below). A web application that is programatically |
255 |
deployed with the deployer may include a Context Desciptor in |
256 |
<code>/META-INF/context.xml</code>. |
257 |
</p> |
258 |
|
259 |
<p> |
260 |
The TCD includes a ready-to-use Ant script, with the following targets: |
261 |
</p> |
262 |
<ul> |
263 |
<li> |
264 |
<code>compile</code> (default): Compile and validate the web |
265 |
application. This can be used standalone, and does not need a running |
266 |
Tomcat server. The compiled application will only run on the associated |
267 |
Tomcat 5.5.x server release, and is not guaranteed to work on another |
268 |
Tomcat release, as the code generated by Jasper depends on its runtime |
269 |
component. It should also be noted that this target will also compile |
270 |
automatically any Java source file located in the |
271 |
<code>/WEB-INF/classes</code> folder of the web application.</li> |
272 |
<li> |
273 |
<code>deploy</code>: Deploy a web application (compiled or not) to |
274 |
a Tomcat server. |
275 |
</li> |
276 |
<li><code>undeploy</code>: Undeploy a web application</li> |
277 |
<li><code>start</code>: Start web application</li> |
278 |
<li><code>reload</code>: Reload web application</li> |
279 |
<li><code>stop</code>: Stop web application</li> |
280 |
</ul> |
281 |
|
282 |
<p> |
283 |
In order for the deployment to be configured, create a file |
284 |
called <code>deployer.properties</code> in the TCD installation |
285 |
directory root. In this file, add the following name=value pairs per |
286 |
line: |
287 |
</p> |
288 |
|
289 |
<p> |
290 |
Additionally, you will need to ensure that a user has been |
291 |
setup for the target Tomcat Manager (which TCD uses) otherwise the TCD |
292 |
will not authenticate with the Tomcat Manager and the deployment will |
293 |
fail. To do this, see the Tomcat Manager page. |
294 |
</p> |
295 |
|
296 |
<ul> |
297 |
<li> |
298 |
<code>build</code>: The build folder used will be, by default, |
299 |
<code>${build}/webapp/${path}</code>. After the end of the execution |
300 |
of the <code>compile</code> target, the web application .WAR will be |
301 |
located at <code>${build}/webapp/${path}.war</code>. |
302 |
</li> |
303 |
<li> |
304 |
<code>webapp</code>: The directory containing the exploded web application |
305 |
which will be compiled and validated. By default, the folder is |
306 |
<code>myapp</code>. |
307 |
</li> |
308 |
<li> |
309 |
<code>path</code>: Deployed context path of the web application, |
310 |
by default <code>/myapp</code>. |
311 |
</li> |
312 |
<li> |
313 |
<code>url</code>: Absolute URL to the Tomcat Manager web application of a |
314 |
running Tomcat server, which will be used to deploy and undeploy the |
315 |
web application. By default, the deployer will attempt to access |
316 |
a Tomcat instance running on localhost, at |
317 |
<code>http://localhost:8080/manager</code>. |
318 |
</li> |
319 |
<li> |
320 |
<code>username</code>: Tomcat Manager username (user should have a role of |
321 |
manager) |
322 |
</li> |
323 |
<li><code>password</code>: Tomcat Manager password.</li> |
324 |
</ul> |
325 |
</section> |
178 |
|
326 |
|
179 |
</body> |
327 |
</body> |
180 |
|
328 |
|