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

Categories

Currently if i deploy a war file on tomcat named say myapp.war, I can access its url by http://localhost/myapp/MyServlet.

However what I want is to deploy a war with a version number in the war file name and still have the same url. For eg, I want to deploy myapp-1.1.0.war and still have the url be http://localhost/myapp/MyServlet

Of course I need to keep updating the war and the version number will keep changing, so I cant hardcode the war filename anywhere. Is there any setting in web.xml I can use to keep the same url for the app regardless of the war filename?

See Question&Answers more detail:os

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

1 Answer

The solution is to stop using the automatic deployment feature of Tomcat, which takes the shortcut of setting the "context name" (the /myapp part of the URL) to the portion of the WAR filename before ".war".

Instead, extract the WAR contents to the filesystem yourself and setup an XML file at TOMCAT_HOME/conf/[enginename]/[hostname]/[contextname].xml which points the desired context path (such as /myapp) to the location of the application on disk (such as /opt/webapps/myapp-1.1.0/).

The Tomcat reference docs provide a good explanation of how Tomcat deploys applications automatically, and how you can configure customized logic for the mapping of context path to application file location (there are a handful of alternate ways to set this up other than the one I suggest above).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...