How to specify path in META-INF/context.xml for Tomcat

前端 未结 4 1953
-上瘾入骨i
-上瘾入骨i 2021-02-05 14:05

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

相关标签:
4条回答
  • 2021-02-05 14:50

    In /tomcat7/conf/server.xml add below lines inside the element and restart Tomcat to make changes take place.

    *change "mycom" to your application name.

    <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>
    

    This will make the default root application appear under context root "/ROOT".

    Now your app is accessible at "/" and "/mycom" as well!

    0 讨论(0)
  • 2021-02-05 14:56

    add copyXML="true" to Host config inside $TOMCAT_HOME/conf/server.xml like

    <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true" copyXML="true">
    
    0 讨论(0)
  • 2021-02-05 14:58

    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>
    
    0 讨论(0)
  • 2021-02-05 15:00

    If you load your application.war to a directory Tomcat isn'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 more on how to set up JNDI in Tomcat

    0 讨论(0)
提交回复
热议问题