Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

mapping - How can I map multiple contexts to the same war file in Tomcat?

I'm using tomcat to deploy my applications, I would like to deploy as one single war to should server multiple context paths.

Currently I have app1.war and app2.war, but both has same contents only name is different to access via http:///app1 and http:///app1.war. But I would like to do this, Deploy app.war and access it by both app1 and app2 context path. Is it possible to do in tomcat? Please help me out of this

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This can be done in several ways. I think this way is the most straightforward:

  1. Move the WAR file outside of the webapps/ auto-deploy directory
  2. Extract META-INF/context.xml from your WAR file. If your WAR doesn't have a META-INF/context.xml file, just use a file with nothing but <Context /> in it
  3. Copy this file into Tomcat's conf/[service]/[host]/ directory as both app1.xml and app2.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").
  4. Edit both app1.xml and app2.xml and set the docBase attribute for the <Context> element to point to the WAR file you moved in step #1
  5. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...