How to set the context path of a web application in Tomcat 7.0

后端 未结 13 1323
傲寒
傲寒 2020-11-21 23:34

I know that I can rename my webapp (or it\'s WAR file) to ROOT but this is a terrible way to do it, IMHO. Now I checked out the tomcat doc & it says

相关标签:
13条回答
  • 2020-11-21 23:41

    In Tomcat 9.0, I only have to change the following in the server.xml

    <Context docBase="web" path="/web" reloadable="true" source="org.eclipse.jst.jee.server:web"/>
    

    to

    <Context docBase="web" path="" reloadable="true" source="org.eclipse.jst.jee.server:web"/>
    
    0 讨论(0)
  • 2020-11-21 23:45

    This little code worked for me, using virtual hosts

    <Host name="my.host.name" >
       <Context path="" docBase="/path/to/myapp.war"/>
    </Host>
    
    0 讨论(0)
  • 2020-11-21 23:48

    What you can do is the following;

    Add a file called ROOT.xml in <catalina_home>/conf/Catalina/localhost/

    This ROOT.xml will override the default settings for the root context of the tomcat installation for that engine and host (Catalina and localhost).

    Enter the following to the ROOT.xml file;

    <Context 
      docBase="<yourApp>" 
      path="" 
      reloadable="true" 
    />
    

    Here, <yourApp> is the name of, well, your app.. :)

    And there you go, your application is now the default application and will show up on http://localhost:8080

    However, there is one side effect; your application will be loaded twice. Once for localhost:8080 and once for localhost:8080/yourApp. To fix this you can put your application OUTSIDE <catalina_home>/webapps and use a relative or absolute path in the ROOT.xml's docBase tag. Something like this;

    <Context 
      docBase="/opt/mywebapps/<yourApp>" 
      path="" 
      reloadable="true" 
    />
    

    And then it should be all OK!

    0 讨论(0)
  • 2020-11-21 23:49

    In Tomcat 8.X ,under tomcat home directory /conf/ folder in server.xml you can add <Context> tag under <Host> tag as shown below . But you have to restart the server in order to take effect

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    
         <Context docBase="${catalina.base}\webapps\<Your App Directory Name>" path="<your app path you wish>" reloadable="true" />
      </Host>
    

    OR if you are using Tomcat 7.X you can add context.xml file in WEB-INF folder in your project . The contents of the file i used is as shown . and it worked fine for me . you don't have to restart server in this case .

    <?xml version="1.0" encoding="UTF-8"?>
    
    <Context docBase="${catalina.base}\webapps\<My App Directory Name>" path="<your app path you wish>" reloadable="true" />
    
    0 讨论(0)
  • 2020-11-21 23:50

    Here follows the only solutions that worked for me. Add this to the Host node in the conf/server.xml

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

    go to Tomcat server.xml file and set path blank

    0 讨论(0)
  • 2020-11-21 23:53

    Quickest and may be the best solution is to have below content in <TOMCAT_INSTALL_DIR>/conf/Catalina/localhost/ROOT.xml

    <Context 
      docBase="/your_webapp_location_directory" 
      path="" 
      reloadable="true" 
    />
    

    And your webapp will be available at http://<host>:<port>/

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