Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deployment of Web Application to a Running Tomcat

I would like to collect some best-practices on deployment of a web-application to a running Tomcat. Not long ago I had to describe the deployment process of our web-application and the process appeared rather confusing.

Say, we have an application in a WAR file (foo.war) correctly configured and not requiring additional configuration. In this case, the deployment process is rather easy:

  • Copy the foo.war file to the $CATALINA_HOME/webapps directory. If the application starts correctly, the application will automatically deploy to $CATALINA_HOME/webapps/foo directory.

To undeploy the application:

  • Remove the foo.war file from the $CATALINA_HOME/webapps. If the application unloads correctly, it will be unloaded and the $CATALINA_HOME/webapps/foo will be removed.

Now I want to override some context parameters in my running application. Having read the docs, all I need to do:

  1. Create a context.xml file called foo.xml
  2. Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.

Unfortunately, that did not work: the application would not restart. Empirically, we found out that the only working solution is when the war file is deployed to a location outside the $CATALINA_HOME/webapps. Besides, the default values of the configurable context parameters in the WAR file should be specified in the web.xml, since context.xml in the WAR file is not read when there is a context.xml outside.

Here is an easy example of the foo.xml:

<?xml version='1.0' encoding='utf-8'?>                           
<Context docBase="/path-to-deployment-directory/foo.war">
    <Parameter name="myparam" value="newvalue" override="false"/>
</Context>

Be sure to specify override=false for the parameter if you want the 'newvalue' to override the value specified in the WAR's web.xml. This was not obvious for us.

Thus, to deploy an aplication to a running Tomcat:

  1. Create a context.xml file called foo.xml
  2. Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
  3. Copy the foo.war to the location specified in the docBase of the foo.xml; the application will deploy automatically.

To apply new context parameters:

  • Add the parameter values to the foo.xml and save the file; the application will re-deploy automatically.

To undeploy the application:

  • Remove the foo.xml from the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory

Note that removing the foo.war will also work, but will remove the foo.xml as well.


By now, I have the following questions:

  1. Is it a best-practice at all to deploy a web-application without stopping the tomcat? I heard an opinion that deployment to a running tomcat is never needed since people run each application in a separate tomcat.
  2. Is it a good idea to copy WAR files to $CATALINA_HOME/webapps or they should better be kept in a separate location?
  3. How can I configure an application deployed to $CATALINA_HOME/webapps
  4. Why there is no INFO line in the catalina.out for deployment of an application and there is one for undeployment? Is it configurable?
like image 335
newtover Avatar asked Feb 24 '09 11:02

newtover


People also ask

What is deployment in Tomcat?

Deployment is the term used for the process of installing a web application (either a 3rd party WAR or your own custom web application) into the Tomcat server. Web application deployment may be accomplished in a number of ways within the Tomcat server. Statically; the web application is setup before Tomcat is started.

How many ways we can deploy the application into Tomcat?

As we can see, there are two ways for deploying a web application using the manager: Deploy directory or WAR file located on server. WAR file to deploy.


1 Answers

On question (1), Tomcat works great for deploying servlets into a running server. There may be concerns w.r.t. security or possibly D.O.S. or provisioning reasons why you would have separate server instances.

You have the flexibility to do either way, but it is often more convenient to deploy to an already running server. This is a BUILT-IN feature in the servlet architecture. :)

For (2), again it is at your discretion where you you want to put WARs. It sounds like you already have it configured a non-standard (non-default I should say) way. Check your server.xml file for the settings in your server instance(s). Check for attributes like unpackWARs and autoDeploy.

For (3) and (4), plus your (1,2) questions, it might be a good idea to consult the Tomcat docs for your version of Tomcat on its deployment model. You should be able to use the same docs to figure out how your server has been configured.

See Tomcat Web Application Deployment in the Tomcat manual, adjusting for your version of Tomcat.

like image 195
popcnt Avatar answered Sep 21 '22 14:09

popcnt