servlet context to tomcat 7 root

后端 未结 3 2020
故里飘歌
故里飘歌 2021-01-13 23:56

Whats the best approach to place servlet context to tomcat 7 root? I have tried this post here but didn\'t work for me; i\'m using Apache Tomcat/7.0.42

相关标签:
3条回答
  • 2021-01-14 00:21

    In your Tomcat's conf/server.xml file, you'll typically have an entry

    <Context docBase="yourApp" path="/somePath" reloadable="true" source="someSource"/>
    

    for your application.

    Change the path to /

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

    Add this in the Host entry. For example

    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    <Context docBase="yourApp" path="/" reloadable="true" />
    </Host>
    

    where the docBase attribute is the name of your app as it appears in the webapps folder. The docs explain the meaning of each attribute.

    0 讨论(0)
  • 2021-01-14 00:22

    check the context documentation. You're looking for the docBase attribute for your webapp's path and the path attribute for the root context, e.g. leave it empty as described in the attribute's documentation.

    0 讨论(0)
  • 2021-01-14 00:26

    Without changing the .war file to ROOT follow below steps:

    1. Create a file named ROOT.xml under the tomcat/conf/Catalina/localhost/

    2. paste below code into the ROOT.xml file:

    <Context
      docBase="/home/user/YOUR_PROJECT/target/YOUR_PROJECT.war"
      path=""
      reloadable="true"
    />
    

    Now you can access your project in tomcat root.

    To have a clean project remove tomcat/webapps/ROOT directory.

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