如何指定“上下文路径"在java war文件中的META-INF/context.xml中的T​​omcat 8上? [英] How can I specify "Context path" on Tomcat 8 inside META-INF/context.xml in java war file?

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

问题描述

如何使用Tomcat 8上war文件中的context.xml将 mywebapp-1.0.0.war 部署到具有上下文路径/mywebapp 的$ TOMCAT_HOME/webapps目录中?

How can I deploy mywebapp-1.0.0.war to $TOMCAT_HOME/webapps directory with context path /mywebapp using context.xml inside the war file on Tomcat 8?

从版本5开始很长一段时间后,我又恢复使用Tomcat.我习惯在我的war文件中创建META-INF/context.xml:

I'm getting back to work with Tomcat after long time since version 5. I'm used to create META-INF/context.xml inside my war file:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/mywebapp">
  ...
</Context>

Maven使用以下名称创建一个战争文件:mywebapp-1.0.0.war

Maven creates a war file with this name: mywebapp-1.0.0.war

但是,当我将war文件部署到$ TOMCAT_HOME/webapps目录时,上下文路径将为 http://localhost:8080/mywebapp-1.0.0 而不是 http://localhost:8080/mywebapp//.

But when I deploy the war file to $TOMCAT_HOME/webapps directory the context path will be http://localhost:8080/mywebapp-1.0.0 instead of http://localhost:8080/mywebapp/.

我还看到$ TOMCAT_HOME/conf/Catalina/localhost为空,而不是从war文件中复制xml文件.

Also I see that $TOMCAT_HOME/conf/Catalina/localhost is empty, instead of having the xml file copied from the war file deployed.

我还将$ deployXML ="true"添加到$ TOMCAT_HOME/conf/server.xml

I also added to $TOMCAT_HOME/conf/server.xml the deployXML="true"

 <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true" 
        deployXML="true">

推荐答案

无法在 webapp 目录中放置战争并在META中设置 path 属性-INF/context.xml文件在同一时间.Tomcat 8 文档明确说明了此属性:

It is not possible to put a war inside the webapp directory and set the path attribute in META-INF/context.xml file at the same time. Tomcat 8 documentation, clearly says about this attribute:

仅当在server.xml中静态定义Context时,才必须使用此属性.在所有其他情况下,将从用于.xml上下文文件或docBase的文件名中推断出路径.

This attribute must only be used when statically defining a Context in server.xml. In all other circumstances, the path will be inferred from the filenames used for either the .xml context file or the docBase.

这篇关于如何指定“上下文路径"在java war文件中的META-INF/context.xml中的T​​omcat 8上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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