如何在 Tomcat 的 META-INF/context.xml 中指定路径 [英] How to specify path in META-INF/context.xml for Tomcat

查看:49
本文介绍了如何在 Tomcat 的 META-INF/context.xml 中指定路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tomcat 7,并希望在 war 文件本身中设置一个 war 文件的上下文根,并让 Tomcat 自动部署并选择此路径.我以为我找到了通过将 context.xml 放在包含的战争的 META-INF 目录中来做到这一点的方法.

但这似乎不起作用,我认为它是由 http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/SetContextPropertiesRule.html 声明它加载除路径之外的所有内容!

我知道我可以将战争命名为 somepath#myapp.war 并且它会接收它,但我也部署到 weblogic,它对这样的名称不满意.

是否有一些设置可以用来让路径从上面的 context.xml 工作?

谢谢大卫

解决方案

除非在 Context 中的硬编码 Context 中指定路径,否则忽略 Context path 属性code>server.xml,强烈建议不要使用,并且不采用多级路径.

war文件名,或者tomcat/conf/Catalina/hostname中的Context xml文件名成为部署应用的path.>

在您的情况下,以上两个中的后者是解决方案,只需确保将 .war 文件放在为主机指定的 appBase 之外,或者您将部署应用两次.

在:conf/Catalina/localhost/myapp#path.xml

<Context docBase="/some/path/to/myapp.war">

I'm using Tomcat 7 and would like to set the context root of a war file in the war file itself and have Tomcat autodeploy and pick up this path. I thought I found the way to do it by putting a context.xml in the META-INF directory of the war which contains.

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/somepath/myapp"/>

But this doesn't seem to work, I think it's loaded by http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/SetContextPropertiesRule.html which states it loads everything but the path!

I know I can name the war somepath#myapp.war and it will pick it up but I also deploy to weblogic which isn't happy with a name like this.

Is there some setting I can use to have the path work from the context.xml above?

Thanks David

解决方案

The Context path attribute is ignored unless the path is specified in a hard-coded Context in server.xml, which is strongly discouraged, and doesn't take multilevel paths.

The name of the war file, or the name of the Context xml file in tomcat/conf/Catalina/hostname becomes the path of the deployed application.

In your case the latter of the two above is the solution, just make sure you put the .war file outside of the designated appBase for the Host, or you'll deploy the app twice.

In: conf/Catalina/localhost/myapp#path.xml

<?xml version="1.0"?>
<Context docBase="/some/path/to/myapp.war">
</Context>

这篇关于如何在 Tomcat 的 META-INF/context.xml 中指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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