This can be done in several ways. I think this way is the most straightforward:
- Move the WAR file outside of the
webapps/
auto-deploy directory - Extract
META-INF/context.xml
from your WAR file. If your WAR doesn’t have aMETA-INF/context.xml
file, just use a file with nothing but<Context />
in it - Copy this file into Tomcat’s
conf/[service]/[host]/
directory as bothapp1.xml
andapp2.xml
. (The [service] is usually “Catalina” and the [host] is whatever the name of your virtual host is: on a default Tomcat configuration, the hostname is always “localhost”). - Edit both
app1.xml
andapp2.xml
and set thedocBase
attribute for the<Context>
element to point to the WAR file you moved in step #1 - Re-start Tomcat
This ought to give you a single physical WAR file and multiple contexts deployed from it.
Although Tomcat supports this configuration, I recommend against it: disk space is cheap, it changes nothing at runtime (you still get two copies of everything in memory), and you lose the flexibility of deploying different WAR files to different contexts and/or updating them separately without modifying the configuration of both contexts.
If you want my advice, stick to duplicate WAR files.