|
Tomcat example source code file (manager-howto.xml)
This example Tomcat source code file (manager-howto.xml) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.
The Tomcat manager-howto.xml source code
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE document [
<!ENTITY project SYSTEM "project.xml">
]>
<document url="manager-howto.html">
&project;
<properties>
<author email="craigmcc@apache.org">Craig R. McClanahan
<title>Manager App HOW-TO
</properties>
<body>
<section name="Table of Contents">
<p>
<a href="#Introduction">Introduction
<a href="#Configuring Manager Application Access">
Configuring Manager Application Access</a>
<a href="#Supported Manager Commands">Supported Manager Commands
<blockquote>
<a href="#Deploy A New Application Remotely">Deploy A New Application Remotely
<a href="#Deploy A New Application from a Local Path">Deploy A New Application from a Local Path
<a href="#List Currently Deployed Applications">
List Currently Deployed Applications</a>
<a href="#Reload An Existing Application">Reload An Existing Application
<a href="#List OS and JVM Properties">List OS and JVM Properties
<a href="#List Available Global JNDI Resources">
List Available Global JNDI Resources</a>
<a href="#List Available Security Roles">List Available Security Roles
<a href="#Session Statistics">Session Statistics
<a href="#Start an Existing Application">Start an Existing Application
<a href="#Stop an Existing Application">Stop an Existing Application
<a href="#Undeploy an Existing Application">
Undeploy an Existing Application</a>
</blockquote>
<a href="#Executing Manager Commands With Ant">
Executing Manager Commands With Ant</a>
<a href="#Using the JMX Proxy Servlet">
Using the JMX Proxy Servlet</a>
<blockquote>
<a href="#What is JMX Proxy Servlet">What is JMX Proxy Servlet?
<a href="#JMX Query command">Query command
<a href="#JMX Set command">Set command
</blockquote>
</p>
</section>
<section name="Introduction">
<p>In many production environments, it is very useful to have the capability
to deploy a new web application, or undeploy an existing one, without having
to shut down and restart the entire container. In addition, you can request
an existing application to reload itself, even if you have not declared it
to be <code>reloadable in the Tomcat 6 server
configuration file.</p>
<p>To support these capabilities, Tomcat 6 includes a web application
(installed by default on context path <code>/manager) that supports
the following functions:</p>
<ul>
<li>Deploy a new web application from the uploaded contents of a WAR file.
<li>Deploy a new web application, on a specified context path, from the
server file system.</li>
<li>List the currently deployed web applications, as well as the
sessions that are currently active for those web apps.</li>
<li>Reload an existing web application, to reflect changes in the
contents of <code>/WEB-INF/classes or /WEB-INF/lib .
</li>
<li>List the OS and JVM property values.
<li>List the available global JNDI resources, for use in deployment
tools that are preparing <code><ResourceLink> elements
nested in a <code><Context> deployment description.
<li>List the available security roles defined in the user database.
<li>Start a stopped application (thus making it available again).
<li>Stop an existing application (so that it becomes unavailable), but
do not undeploy it.</li>
<li>Undeploy a deployed web application and delete its document base
directory (unless it was deployed from file system).</li>
</ul>
<p>A default Tomcat installation includes the manager. To add an instance of the
Manager web application <code>Context to a new host install the
<code>manager.xml context configuration file in the
<code>$CATALINA_HOME/conf/[enginename]/[hostname] folder. Here is an
example:
<pre>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/kinetic/tomcat6/server/webapps/manager">
</Context>
</pre>
</p>
<p>If you have Tomcat configured to support multiple virtual hosts
(websites) you would need to configure a Manager for each.</p>
<p>There are three ways to use the Manager web application.
<ul>
<li>As an application with a user interface you use in your browser.
Here is an example URL where you can replace <code>localhost with
your website host name: <code>http://localhost/manager/html/ .
<li>A minimal version using HTTP requests only which is suitable for use
by scripts setup by system administrators. Commands are given as part of the
request URI, and responses are in the form of simple text that can be easily
parsed and processed. See <a href="#Supported Manager Commands">
Supported Manager Commands</a> for more information.
<li>A convenient set of task definitions for the Ant
(version 1.4 or later) build tool. See
<a href="#Executing Manager Commands With Ant">Executing Manager Commands
With Ant</a> for more information.
</ul>
</p>
</section>
<section name="Configuring Manager Application Access">
<blockquote>
<p>The description below uses the variable name $CATALINA_HOME
to refer to the directory into which you have installed Tomcat 6,
and is the base directory against which most relative paths are
resolved. However, if you have configured Tomcat 6 for multiple
instances by setting a CATALINA_BASE directory, you should use
$CATALINA_BASE instead of $CATALINA_HOME for each of these
references.</p>
</em>
<p>It would be quite unsafe to ship Tomcat with default settings that allowed
anyone on the Internet to execute the Manager application on your server.
Therefore, the Manager application is shipped with the requirement that anyone
who attempts to use it must authenticate themselves, using a username and
password that have the role <strong>manager associated with them.
Further, there is no username in the default users file
(<conf>$CATALINA_HOME/conf/tomcat-users.xml) that is assigned this
role. Therefore, access to the Manager application is completely disabled
by default.</p>
<p>To enable access to the Manager web application, you must either create
a new username/password combination and associate the role name
<strong>manager with it, or add the manager role
to some existing username/password combination. Exactly where this is done
depends on which <code>Realm implementation you are using:
<ul>
<li>MemoryRealm - If you have not customized your
<code>$CATALINA_HOME/conf/server.xml to select a different one,
Tomcat 6 defaults to an XML-format file stored at
<code>$CATALINA_HOME/conf/tomcat-users.xml, which can be
edited with any text editor. This file contains an XML
<code><user> for each individual user, which might
look something like this:
<source>
<user name="craigmcc" password="secret" roles="standard,manager" />
</source>
which defines the username and password used by this individual to
log on, and the role names he or she is associated with. You can
add the <strong>manager role to the comma-delimited
<code>roles attribute for one or more existing users, and/or
create new users with that assigned role.</li>
<li>JDBCRealm - Your user and role information is stored in
a database accessed via JDBC. Add the <strong>manager role
to one or more existing users, and/or create one or more new users
with this role assigned, following the standard procedures for your
environment.</li>
<li>JNDIRealm - Your user and role information is stored in
a directory server accessed via LDAP. Add the <strong>manager
role to one or more existing users, and/or create one or more new users
with this role assigned, following the standard procedures for your
environment.</li>
</ul>
<p>The first time you attempt to issue one of the Manager commands
described in the next section, you will be challenged to log on using
BASIC authentication. The username and password you enter do not matter,
as long as they identify a valid user in the users database who possesses
the role <strong>manager.
<p>In addition to the password restrictions the manager web application
could be restricted by the remote IP address or host by adding a
<code>RemoteAddrValve or RemoteHostValve . Here is
an example of restricting access to the localhost by IP address:
<pre>
<Context path="/manager" privileged="true"
docBase="/usr/local/kinetic/tomcat6/server/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.0\.0\.1"/>
</Context>
</pre>
</p>
</section>
<section name="Supported Manager Commands">
<p>All commands that the Manager application knows how to process are
specified in a single request URI like this:</p>
<source>
http://{host}:{port}/manager/{command}?{parameters}
</source>
<p>where {host} and {port} represent the hostname
and port number on which Tomcat is running, <code>{command}
represents the Manager command you wish to execute, and
<code>{parameters} represents the query parameters
that are specific to that command. In the illustrations below, customize
the host and port appropriately for your installation.</p>
<p>Most commands accept one or more of the following query parameters:
<ul>
<li>path - The context path (including the leading slash)
of the web application you are dealing with. To select the ROOT web
application, specify "/". <strong>NOTE -
It is not possible to perform administrative commands on the
Manager application itself.</li>
<li>war - URL of a web application archive (WAR) file,
pathname of a directory which contains the web application, or a
Context configuration ".xml" file. You can use URLs in any of the
following formats:
<ul>
<li>file:/absolute/path/to/a/directory - The absolute
path of a directory that contains the unpacked version of a web
application. This directory will be attached to the context path
you specify without any changes.</li>
<li>file:/absolute/path/to/a/webapp.war - The absolute
path of a web application archive (WAR) file. This is valid
<strong>only for the /deploy command, and is
the only acceptable format to that command.</li>
<li>jar:file:/absolute/path/to/a/warfile.war!/ - The
URL to a local web application archive (WAR) file. You can use any
syntax that is valid for the <code>JarURLConnection class
for reference to an entire JAR file.</li>
<li>file:/absolute/path/to/a/context.xml - The
absolute path of a web application Context configuration ".xml"
file which contains the Context configuration element.</li>
<li>directory - The directory name for the web
applciation context in the Host's application base directory.</li>
<li>webapp.war - The name of a web application war file
located in the Host's application base directory.</li>
</ul>
</ul>
<p>Each command will return a response in text/plain format
(i.e. plain ASCII with no HTML markup), making it easy for both humans and
programs to read). The first line of the response wil begin with either
<code>OK or FAIL , indicating whether the requested
command was successful or not. In the case of failure, the rest of the first
line will contain a description of the problem that was encountered. Some
commands include additional lines of information as described below.</p>
<p>Internationalization Note - The Manager application looks up
its message strings in resource bundles, so it is possible that the strings
have been translated for your platform. The examples below show the English
version of the messages.</p>
<blockquote>
<p>WARNING: the legacy commands /install and
<code>/remove are deprecated.
They are presently equivalent to <code>/deploy and /undeploy ,
but could be removed in a future release.</p>
</em>
<subsection name="Deploy A New Application Remotely">
<source>
http://localhost:8080/manager/deploy?path=/foo
</source>
<p>Upload the web application archive (WAR) file that is specified as the
request data in this HTTP PUT request, install it into the <code>appBase
directory of our corresponding virtual host, and start , using the directory
name or the war file name without the .war extension as the path. The
application can later be undeployed (and the corresponding application directory
removed) by use of the <code>/undeploy command.
<p>The .WAR file may include Tomcat specific deployment configuration, by
including a Context configuration XML file in
<code>/META-INF/context.xml.
<p>URL parameters include:
<ul>
<li>update : When set to true, any existing update will be
undeployed first. The default value is set to false.</li>
<li>tag : Specifying a tag name, this allows associating the
deployed webapp with a version number. The application version can
be later redeployed when needed using only the tag.</li>
</ul>
</p>
<p>NOTE - This command is the logical
opposite of the <code>/undeploy command.
<p>If installation and startup is successful, you will receive a response
like this:</p>
<source>
OK - Deployed application at context path /foo
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Application already exists at path /foo
<blockquote>
<p>The context paths for all currently running web applications must be
unique. Therefore, you must undeploy the existing web
application using this context path, or choose a different context path
for the new one. The <code>update parameter may be specified as
a parameter on the URL, with a value of <code>true to avoid this
error. In that case, an undeploy will be performed on an existing
application before performing the deployment.</p>
</blockquote>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to start the new web application.
Check the Tomcat 6 logs for the details, but likely explanations include
problems parsing your <code>/WEB-INF/web.xml file, or missing
classes encountered when initializing application event listeners and
filters.</p>
</blockquote>
</ul>
</subsection>
<subsection name="Deploy A New Application from a Local Path">
<p>Deploy and start a new web application, attached to the specified context
<code>path (which must not be in use by any other web application).
This command is the logical opposite of the <code>/undeploy command.
<p>There are a number of different ways the deploy command can be used.
<h3>Deploy a version of a previously deployed webapp
<p>This can be used to deploy a previous version of a web application, which
has been deployed using the <code>tag attribute. Note that the work
directory for the manager webapp will contain the previously deployed WARs;
removing it would make the deployment fail.
<source>
http://localhost:8080/manager/deploy?path=/footoo&tag=footag
</source>
</p>
<h3>Deploy a Directory or WAR by URL
<p>Deploy a web application directory or ".war" file located on the Tomcat
server. If no <code>path is specified, the directory name or the war file
name without the ".war" extension is used as the path. The <code>war
parameter specifies a URL (including the <code>file: scheme) for either
a directory or a web application archive (WAR) file. The supported syntax for
a URL referring to a WAR file is described on the Javadocs page for the
<code>java.net.JarURLConnection class. Use only URLs that refer to
the entire WAR file.</p>
<p>In this example the web application located in the directory
<code>/path/to/foo on the Tomcat server is deployed as the
web application context named <code>/footoo.
<source>
http://localhost:8080/manager/deploy?path=/footoo&war=file:/path/to/foo
</source>
</p>
<p>In this example the ".war" file /path/to/bar.war on the
Tomcat server is deployed as the web application context named
<code>/bar. Notice that there is no path parameter
so the context path defaults to the name of the web application archive
file without the ".war" extension.
<source>
http://localhost:8080/manager/deploy?war=jar:file:/path/to/bar.war!/
</source>
</p>
<h3>Deploy a Directory or War from the Host appBase
<p>Deploy a web application directory or ".war" file located in your Host
appBase directory. The directory name or the war file name without the ".war"
extension is used as the path.</p>
<p>In this example the web application located in a sub directory named
<code>foo in the Host appBase directory of the Tomcat server is
deployed as the web application context named <code>/foo. Notice
that the context path used is the name of the web application directory.
<source>
http://localhost:8080/manager/deploy?war=foo
</source>
</p>
<p>In this example the ".war" file bar.war located in your
Host appBase directory on the Tomcat server is deployed as the web
application context named <code>/bar.
<source>
http://localhost:8080/manager/deploy?war=bar.war
</source>
</p>
<h3>Deploy using a Context configuration ".xml" file
<p>If the Host deployXML flag is set to true you can deploy a web
application using a Context configuration ".xml" file and an optional
".war" file or web application directory. The context <code>path
is not used when deploying a web application using a context ".xml"
configuration file.</p>
<p>A Context configuration ".xml" file can contain valid XML for a
web application Context just as if it were configured in your
Tomcat <code>server.xml configuration file. Here is an
example:
<source>
<Context path="/foobar" docBase="/path/to/application/foobar"
debug="0">
<!-- Link to the user database we will get roles from -->
<ResourceLink name="users" global="UserDatabase"
type="org.apache.catalina.UserDatabase"/>
</Context>
</source>
</p>
<p>When the optional war parameter is set to the URL
for a web application ".war" file or directory it overrides any
docBase configured in the context configuration ".xml" file.</p>
<p>Here is an example of deploying an application using a Context
configuration ".xml" file.
<source>
http://localhost:8080/manager/deploy?config=file:/path/context.xml
</source>
</p>
<p>Here is an example of deploying an application using a Context
configuration ".xml" file and a web application ".war" file located
on the server.
<source>
http://localhost:8080/manager/deploy?config=file:/path/context.xml&war=jar:file:/path/bar.war!/
</source>
</p>
<h3>Deployment Notes
<p>If the Host is configured with unpackWARs=true and you deploy a war
file, the war will be unpacked into a directory in your Host appBase
directory.</p>
<p>If the application war or directory is installed in your Host appBase
directory and either the Host is configured with autoDeploy=true or
liveDeploy=true, the Context path must match the directory name or
war file name without the ".war" extension.</p>
<p>For security when untrusted users can manage web applications, the
Host deployXML flag can be set to false. This prevents untrusted users
from deploying web applications using a configuration XML file and
also prevents them from deploying application directories or ".war"
files located outside of their Host appBase.</p>
<h3>Deploy Response
<p>If installation and startup is successful, you will receive a response
like this:</p>
<source>
OK - Deployed application at context path /foo
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Application already exists at path /foo
<blockquote>
<p>The context paths for all currently running web applications must be
unique. Therefore, you must undeploy the existing web
application using this context path, or choose a different context path
for the new one. The <code>update parameter may be specified as
a parameter on the URL, with a value of <code>true to avoid this
error. In that case, an undeploy will be performed on an existing
application before performing the deployment.</p>
</blockquote>
<li>Document base does not exist or is not a readable directory
<blockquote>
<p>The URL specified by the war parameter must identify a
directory on this server that contains the "unpacked" version of a
web application, or the absolute URL of a web application archive (WAR)
file that contains this application. Correct the value specified by
the <code>war parameter.
</blockquote>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to start the new web application.
Check the Tomcat 6 logs for the details, but likely explanations include
problems parsing your <code>/WEB-INF/web.xml file, or missing
classes encountered when initializing application event listeners and
filters.</p>
</blockquote>
<li>Invalid application URL was specified
<blockquote>
<p>The URL for the directory or web application that you specified
was not valid. Such URLs must start with <code>file:, and URLs
for a WAR file must end in ".war".</p>
</blockquote>
<li>Invalid context path was specified
<blockquote>
<p>The context path must start with a slash character. To reference the
ROOT web application use "/".</p>
</blockquote>
<li>Context path must match the directory or WAR file name:
<blockquote>
If the application war or directory is installed in your Host appBase
directory and either the Host is configured with autoDeploy=true or
liveDeploy=true, the Context path must match the directory name or
war file name without the ".war" extension.
</blockquote>
<li>Only web applications in the Host web application directory can
be installed</em>
<blockquote>
If the Host deployXML flag is set to false this error will happen
if an attempt is made to deploy a web application directory or
".war" file outside of the Host appBase directory.
</blockquote>
</ul>
</subsection>
<subsection name="List Currently Deployed Applications">
<source>
http://localhost:8080/manager/list
</source>
<p>List the context paths, current status (running or
<code>stopped), and number of active sessions for all currently
deployed web applications. A typical response immediately
after starting Tomcat might look like this:</p>
<source>
OK - Listed applications for virtual host localhost
/webdav:running:0
/examples:running:0
/manager:running:0
/:running:0
</source>
</subsection>
<subsection name="Reload An Existing Application">
<source>
http://localhost:8080/manager/reload?path=/examples
</source>
<p>Signal an existing application to shut itself down and reload. This can
be useful when the web application context is not reloadable and you have
updated classes or property files in the <code>/WEB-INF/classes
directory or when you have added or updated jar files in the
<code>/WEB-INF/lib directory.
</p>
<p>NOTE: The /WEB-INF/web.xml
web application configuration file is not reread on a reload.
If you have made changes to your web.xml file you must stop
then start the web application.
</p>
<p>If this command succeeds, you will see a response like this:
<source>
OK - Reloaded application at context path /examples
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to restart the web application.
Check the Tomcat 6 logs for the details.</p>
</blockquote>
<li>Invalid context path was specified
<blockquote>
<p>The context path must start with a slash character. To reference the
ROOT web application use "/".</p>
</blockquote>
<li>No context exists for path /foo
<blockquote>
<p>There is no deployed application on the context path
that you specified.</p>
</blockquote>
<li>No context path was specified
<blockquote>
The <code>path parameter is required.
</blockquote>
<li>Reload not supported on WAR deployed at path /foo
<blockquote>
Currently, application reloading (to pick up changes to the classes or
<code>web.xml file) is not supported when a web application is
deployed directly from a WAR file. It only works when the web application
is deployed from an unpacked directory. If you are using a WAR file,
you should <code>undeploy and then deploy or
<code>deploy with the update parameter the
application again to pick up your changes.
</blockquote>
</ul>
</subsection>
<subsection name="List OS and JVM Properties">
<source>
http://localhost:8080/manager/serverinfo
</source>
<p>Lists information about the Tomcat version, OS, and JVM properties.
<p>If an error occurs, the response will start with FAIL and
include an error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to enumerate the system properties.
Check the Tomcat 6 logs for the details.</p>
</blockquote>
</ul>
</subsection>
<subsection name="List Available Global JNDI Resources">
<source>
http://localhost:8080/manager/resources[?type=xxxxx]
</source>
<p>List the global JNDI resources that are available for use in resource
links for context configuration files. If you specify the <code>type
request parameter, the value must be the fully qualified Java class name of
the resource type you are interested in (for example, you would specify
<code>javax.sql.DataSource to acquire the names of all available
JDBC data sources). If you do not specify the <code>type request
parameter, resources of all types will be returned.</p>
<p>Depending on whether the type request parameter is specfied
or not, the first line of a normal response will be:</p>
<pre>
OK - Listed global resources of all types
</pre>
<p>or
<pre>
OK - Listed global resources of type xxxxx
</pre>
<p>followed by one line for each resource. Each line is composed of fields
delimited by colon characters (":"), as follows:</p>
<ul>
<li>Global Resource Name - The name of this global JNDI resource,
which would be used in the <code>global attribute of a
<code><ResourceLink> element.
<li>Global Resource Type - The fully qualified Java class name of
this global JNDI resource.</li>
</ul>
<p>If an error occurs, the response will start with FAIL and
include an error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to enumerate the global JNDI
resources. Check the Tomcat 6 logs for the details.</p>
</blockquote>
<li>No global JNDI resources are available
<blockquote>
<p>The Tomcat server you are running has been configured without
global JNDI resources.</p>
</blockquote>
</ul>
</subsection>
<subsection name="List Available Security Roles">
<source>
http://localhost:8080/manager/roles
</source>
<p>List the security role names (and corresponding descriptions) that are
available in the <code>org.apache.catalina.UserDatabase resource that
is linked to the <code>users resource reference in the web.xml file
for the Manager web application. This would typically be used, for example,
by a deployment tool that wanted to create
<code><security-role-ref> elements to map security role names
used in a web application to the role names actually defined within the
container.</p>
<p>By default, the users resource reference is pointed at the
global <code>UserDatabase resource. If you choose to utilize a
different user database per virtual host, you should modify the
<code><ResourceLink> element in the default
<code>manager.xml context configuration file to point at the global
user database resource for this virtual host.</p>
<p>When this command is executed, the first line of the response will be:
<pre>
OK - Listed security roles
</pre>
<p>followed by one line for each security role. Each line is composed of
fields delimited by colon characters (":") as follows:</p>
<ul>
<li>Security Role Name - A security role name that is known to Tomcat
in the user database.</li>
<li>Description - Description of this security role (useful in
creating user interfaces for selecting roles.</li>
</ul>
<p>If an error occurs, the response will start with FAIL and
include an error message. Possible causes for problems include:</p>
<ul>
<li>Cannot resolve user database reference - A JNDI error prevented
the successful lookup of the <code>org.apache.catalina.UserDatabase
resource. Check the Tomcat log files for a stack trace associated with
this error.</li>
<li>No user database is available - You have not configured a resource
reference for the <code>users resource that points at an
appropriate user database instance. Check your <code>manager.xml
file and ensure that you have created an appropriate
<code><ResourceLink> or
<code><ResourceParams> element for this resource.
</ul>
</subsection>
<subsection name="Session Statistics">
<source>
http://localhost:8080/manager/sessions?path=/examples
</source>
<p>Display the default session timeout for a web application, and the
number of currently active sessions that fall within ten-minute ranges of
their actual timeout times. For example, after restarting Tomcat and then
executing one of the JSP samples in the <code>/examples web app,
you might get something like this:</p>
<source>
OK - Session information for application at context path /examples
Default maximum session inactive interval 30 minutes
30 - <40 minutes:1 sessions
</source>
</subsection>
<subsection name="Start an Existing Application">
<source>
http://localhost:8080/manager/start?path=/examples
</source>
<p>Signal a stopped application to restart, and make itself available again.
Stopping and starting is useful, for example, if the database required by
your application becomes temporarily unavailable. It is usually better to
stop the web application that relies on this database rather than letting
users continuously encounter database exceptions.</p>
<p>If this command succeeds, you will see a response like this:
<source>
OK - Started application at context path /examples
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to start the web application.
Check the Tomcat 6 logs for the details.</p>
</blockquote>
<li>Invalid context path was specified
<blockquote>
<p>The context path must start with a slash character. To reference the
ROOT web application use "/".</p>
</blockquote>
<li>No context exists for path /foo
<blockquote>
<p>There is no deployed application on the context path
that you specified.</p>
</blockquote>
<li>No context path was specified
<blockquote>
The <code>path parameter is required.
</blockquote>
</ul>
</subsection>
<subsection name="Stop an Existing Application">
<source>
http://localhost:8080/manager/stop?path=/examples
</source>
<p>Signal an existing application to make itself unavailable, but leave it
deployed. Any request that comes in while an application is
stopped will see an HTTP error 404, and this application will show as
"stopped" on a list applications command.</p>
<p>If this command succeeds, you will see a response like this:
<source>
OK - Stopped application at context path /examples
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to stop the web application.
Check the Tomcat 6 logs for the details.</p>
</blockquote>
<li>Invalid context path was specified
<blockquote>
<p>The context path must start with a slash character. To reference the
ROOT web application use "/".</p>
</blockquote>
<li>No context exists for path /foo
<blockquote>
<p>There is no deployed application on the context path
that you specified.</p>
</blockquote>
<li>No context path was specified
<blockquote>
The <code>path parameter is required.
</blockquote>
</ul>
</subsection>
<subsection name="Undeploy an Existing Application">
<source>
http://localhost:8080/manager/undeploy?path=/examples
</source>
<p>WARNING - This command will delete any web
application artifacts that exist within <code>appBase directory
(typically "webapps") for this virtual host</strong>.
This will delete the the application .WAR, if present,
the application directory resulting either from a deploy in unpacked form
or from .WAR expansion as well as the XML Context definition from
<code>$CATALINA_HOME/conf/[enginename]/[hostname]/ directory.
If you simply want to take an application
out of service, you should use the <code>/stop command instead.
<p>Signal an existing application to gracefully shut itself down, and
remove it from Tomcat (which also makes this context path available for
reuse later). In addition, the document root directory is removed, if it
exists in the <code>appBase directory (typically "webapps") for
this virtual host. This command is the logical opposite of the
<code>/deploy command.
<p>If this command succeeds, you will see a response like this:
<source>
OK - Undeployed application at context path /examples
</source>
<p>Otherwise, the response will start with FAIL and include an
error message. Possible causes for problems include:</p>
<ul>
<li>Encountered exception
<blockquote>
<p>An exception was encountered trying to undeploy the web application.
Check the Tomcat 6 logs for the details.</p>
</blockquote>
<li>Invalid context path was specified
<blockquote>
<p>The context path must start with a slash character. To reference the
ROOT web application use "/".</p>
</blockquote>
<li>No context exists for path /foo
<blockquote>
<p>There is no deployed application on the context path
that you specified.</p>
</blockquote>
<li>No context path was specified
<blockquote>
The <code>path parameter is required.
</blockquote>
</ul>
</subsection>
</section>
<section name="Executing Manager Commands With Ant">
<p>In addition to the ability to execute Manager commands via HTTP requests,
as documented above, Tomcat 6 includes a convenient set of Task definitions
for the <em>Ant (version 1.4 or later) build tool. In order to use these
commands, you must perform the following setup operations:</p>
<ul>
<li>Download the binary distribution of Ant from
<a href="http://ant.apache.org">http://ant.apache.org.
You must use version <strong>1.4 or later.
<li>Install the Ant distribution in a convenient directory (called
ANT_HOME in the remainder of these instructions).</li>
<li>Copy the file server/lib/catalina-ant.jar from your Tomcat 6
installation into Ant's library directory (<code>$ANT_HOME/lib).
</li>
<li>Add the $ANT_HOME/bin directory to your PATH
environment variable.</li>
<li>Configure at least one username/password combination in your Tomcat
user database that includes the <code>manager role.
</ul>
<p>To use custom tasks within Ant, you must declare them first with a
<code><taskdef> element. Therefore, your build.xml
file might look something like this:</p>
<table border="1">
<tr>
<project name="My Application" default="compile" basedir=".">
<!-- Configure the directory into which the web application is built -->
<property name="build" value="${basedir}/build"/>
<!-- Configure the context path for this application -->
<property name="path" value="/myapp"/>
<!-- Configure properties to access the Manager application -->
<property name="url" value="http://localhost:8080/manager"/>
<property name="username" value="myusername"/>
<property name="password" value="mypassword"/>
<!-- Configure the custom Ant tasks for the Manager application -->
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask"/>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/>
<taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask"/>
<taskdef name="roles" classname="org.apache.catalina.ant.RolesTask"/>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask"/>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask"/>
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/>
<!-- Executable Targets -->
<target name="compile" description="Compile web application">
<!-- ... construct web application in ${build} subdirectory, and
generated a ${path}.war ... -->
</target>
<target name="deploy" description="Install web application"
depends="compile">
<deploy url="${url}" username="${username}" password="${password}"
path="${path}" war="file:${build}${path}.war"/>
</target>
<target name="reload" description="Reload web application"
depends="compile">
<reload url="${url}" username="${username}" password="${password}"
path="${path}"/>
</target>
<target name="undeploy" description="Remove web application">
<undeploy url="${url}" username="${username}" password="${password}"
path="${path}"/>
</target>
</project>
</pre> | |
</table>
<p>Now, you can execute commands like