使用不同的路径将war文件部署到Tomcat [英] Deploying war file to Tomcat with a different path

查看:104
本文介绍了使用不同的路径将war文件部署到Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将war文件部署到Tomcat,例如 foo-bar-1.1.2.war ,我该如何部署它以便将其提取到 webapps / bar ,其网址为 / bar /...

If I deploy a war file to Tomcat, called for example foo-bar-1.1.2.war, how can I deploy it so that it is extracted to webapps/bar and its URL root is /bar/...?

我的目的是将war文件保存在webapps服务器及其版本信息中,以便我知道安装了哪个版本,但是它会覆盖以前版本的应用程序。

My intention here is to keep the war file in the webapps server with its version information so that I know which version is installed but have it overwrite a previous version of the app.

我可以使用 PSI Probe 部署war文件。这将允许我为Web应用程序指定目标上下文。但是,这意味着我将丢失war文件名中的任何版本信息。

I could deploy the war file using PSI Probe. This would allow me to specify a target context for the web app. However, it means that I would lose any version information in the war file name.

推荐答案

Tomcat将始终提取内容war文件,到同名文件夹(当它被配置为部署战争时 - 默认等)。

Tomcat will always extract the contents of a war file, to a folder of the same name (when it's configured to deploy wars - as default etc.).

你可以将它提取到你选择的文件夹名称。因此,如果您将 foo.war 的内容手动解压缩到名为 bar / 的文件夹中,而不是仅仅放弃战争进入Web应用程序文件夹,它仍然会加载Web应用程序。

You can extract it to a folder name of your choice. So if you unzip the contents of foo.war to a folder called bar/ manually, instead of just dropping the war into the web apps folder, it'll still load the web application.

但是,这完全没必要,因为您可以指定应用程序的URL模式而不会弄乱通过覆盖应用程序的上下文根元素来完全删除文件夹/ war文件名:

However, this is totally unnecessary as you can specify the URL pattern of the application without messing with the folder / war file name at all by overriding the context root element for your application:

这通常在Tomcat server.xml中设置 - 但这种做法被广泛劝阻。相反,我建议您在Web应用程序/ war文件的META-INF文件夹中使用 context.xml

This is often set in the Tomcat server.xml - but that practice is fairly widely discouraged. Instead, I'd suggest you use context.xml in the META-INF folder of your web application / war file:

<Context path="/bar" .../>

部署应用程序时, context.xml 应复制到 / conf / Catalina / localhost ,但重命名为 foo.xml

When the application is deployed, the context.xml should be copied to /conf/Catalina/localhost but renamed to foo.xml

请注意,conext根必须是唯一的,如果您使用 autoDeploy deployOnStartup,还有一些其他注意事项操作(来源 http://tomcat.apache .org / tomcat-7.0-doc / config / context.html )。

Note that conext roots must be unique and there are some additional considerations if you're using the autoDeploy or deployOnStartup operations (Source http://tomcat.apache.org/tomcat-7.0-doc/config/context.html).

其他选项包括:


  • 清理每个部署的web apps文件夹并删除新的 foo-1.1.0 战争。

  • 在平面文件中包含版本号。 foo / version1

  • 或者只是在config / XML文件中包含该版本。

  • Clean the web apps folder each deployment and drop your new foo-1.1.0 war in.
  • Include the version number in a flat file. foo/version1
  • Or simply include the version in a config / XML file.

您还可以使用Ant(或等效工具)自动部署(并执行上述任何操作)。

You could also use Ant (or an equivalent tool) to automate your deployments (and perform any of the above).

这篇关于使用不同的路径将war文件部署到Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆