将war应用程序名称与war文件名分隔开 [英] Separating war application name from war file name
问题描述
目前,如果我在名为say myapp.war
的tomcat上部署war文件,我可以通过 http:// localhost / myapp / MyServlet 。
Currently if i deploy a war file on tomcat named say myapp.war
, I can access its url by http://localhost/myapp/MyServlet.
但我想要的是部署一个版本号的战争在war文件名中仍然有相同的url。
例如,我想部署 myapp-1.1.0.war
并且仍然有网址 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
当然我需要不断更新战争,版本号将会不断改变,所以我不能在任何地方硬编码war文件名。
web.xml
中是否有任何设置我可以用来为应用保留相同的网址而不管war文件名?
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?
推荐答案
解决方案是停止使用Tomcat的自动部署功能,它采用设置上下文名称的快捷方式( / myapp
URL的一部分)到.war之前的WAR文件名部分。
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".
相反,将WAR内容解压缩到文件系统自己并在 TOMCAT_HOME / conf / [enginename] / [hostname] / [contextname] .xml
设置一个XML文件,它指向所需的上下文路径(例如 / myapp
)到磁盘上应用程序的位置(例如 /opt/webapps/myapp-1.1.0 /
)。
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/
).
Tomcat参考文档可以很好地解释Tomcat如何自动部署应用程序,以及如何配置自定义日志用于将上下文路径映射到应用程序文件位置的ic(除了上面建议的那个之外,还有一些替代方法来设置它。)
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).
这篇关于将war应用程序名称与war文件名分隔开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!