首页 文章

如何在Tomcat的META-INF / context.xml中指定路径

提问于
浏览
13

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

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

但这并没有't seem to work, I think it'由http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/SetContextPropertiesRule.html加载,它声明它除了路径之外还加载了所有东西!

我知道我可以将战争命名为#myapp.war并将它取出来但我也会部署到weblogic,这对于这样的名字并不满意 .

我可以使用一些设置让路径从上面的context.xml开始工作吗?

谢谢大卫

4 回答

  • 13

    除非在 server.xml 中的硬编码 Context 中指定了路径,否则将忽略Context path 属性,这是强烈不鼓励的,并且不采用多级路径 .

    war文件的名称或 tomcat/conf/Catalina/hostname 中的Context xml文件的名称将成为已部署应用程序的 path .

    在您的情况下,上面两个中的后一个是解决方案,只需确保将 .war 文件放在主机的指定 appBase 之外,否则您将部署应用程序两次 .

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

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

    在/tomcat7/conf/server.xml中添加元素内的下面的行并重新启动Tomcat以进行更改 .

    *将“mycom”更改为您的应用程序名称 .

    <Context path="" docBase="mycom">
      <!-- Default set of monitored resources -->
      <WatchedResource>WEB-INF/web.xml</WatchedResource>
    </Context>
    <Context path="ROOT" docBase="ROOT">
      <!-- Default set of monitored resources -->
      <WatchedResource>WEB-INF/web.xml</WatchedResource>
    </Context>
    

    这将使默认根应用程序显示在上下文根“/ ROOT”下 .

    现在您的应用程序也可以通过“/”和“/ mycom”访问!

  • 1

    将copyXML =“true”添加到$ TOMCAT_HOME / conf / server.xml内的Host配置中

    <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true" copyXML="true">
    
  • 2

    如果你将application.war加载到一个目录Tomcat不是't aware of, how can it read anything in your war file? The correct place to add this information is in $TOMCAT_HOME/conf/context.xml - this is part of Tomcat and Tomcat can read this file and find out where your application is and deploy it. There' s更多关于how to set up JNDI in Tomcat

相关问题