Need to run multiple instances of the same web application in Tomcat

Viewed 1656

I am using Tomcat 8.5, with a webapp deployed to the default webapps directory (/var/lib/tomcat8/webpps/MyWebApp.war).

Now I would like to run a second instance of that same webapp. I thought that I could create a new MyWebApp2.xml file in the context directory (/etc/tomcat8/Catalina/localhost/MyWebApp2.xml), and set the appBase="MyWebApp.war", so that I could run the second instance without needing to upload and maintain a separate war file.

However, when I do this, I get this Tomcat error:

docBase [/var/lib/tomcat8/webapps/MyWebApp.war] inside the host appBase has been specified, and will be ignored

It sounds like I could solve this problem by either 1) uploading a separate .war file with a different name, or 2) placing the first .war file outside of the default webapp folder, but I don't like either of these solutions. Shouldn't it be possible to run multiple instances of an application from a single .war file in the default webapps directory?

2 Answers

I am also using Tomcat 8.5 and deploying another instance of the same application is very easy.

All you have to do is make a copy of the war file. There is no need to mess with any configuration file. The path and version of the new instance will be derived from the name of the war file.

For instance, if the war file of the original application is myapp.war, you can simply do this in the webapps directory:

copy myapp.war foo.war

Tomcat will detect the new war file and deploy a new instance at /foo in a few seconds.

To deploy at a deeper path and assign a version, use # and ## respectively. For instance, this:

copy myapp.war foo#bar##9.war

will deploy the application at path /foo/bar and assign the version 9.

Update

You should have mentioned about using Tomcat Client Deployer in your question because my suggestion already fulfills both of your original conditions: 1) without uploading another war file and 2) without putting the war file outside of the webapps directory.

As far as I know, TCD uses Tomcat Manager as the backend and Tomcat Manager only uploads war files to the webapps directory, which explains TCD's restriction. The way I see it, you have three options:

  1. Augment TCD with something else to add more functionality. You mentioned one: ssh.

  2. Use another deployment solution.

  3. Make one. Because you already know exactly what you want, you can simply write some script to make it happen.

Use a descriptor file for each. That is, multiple descriptor files in /conf/Catalina/localhost. Each one gets a different name (app1.xml, app2.xml) so they're deployed at /app1, /app2, etc, but you reference the same .war.

app1.xml:

Context path="/app1" docBase="/path/to/MyWebApp.war" reloadable="false"

app2.xml:

Context path="/app2" docBase="/path/to/MyWebApp.war" reloadable="false"

Related