Tomcat 7 change ROOT application

from http://octodecillion.com/blog/tomcat7-change-root-app/

The default application of a fresh install of Tomcat 7 is ROOT. You want to remove it and use your own?

I’m running a supported Tomcat instance and it’s trial period ended. I’ll just stick with plain old Tomcat.

Perhaps for a business, the enhanced Tomcat (only change is a better management console?) would make more sense. For personal use I just installed version 7.

Maybe they improved the setup experience. I gave up trying to change the default web app from ROOT to my own “home”.

Nope, still makes no sense. You’d think there would be a FAQ or something on this. The kludge way is to just put your app into ROOT. Yuck.

Well, its possible and easy. I found the hint here, in one of the comments.. Thanks Joe!

The trick is that you have to add a context configuration for the default web app AND you CAN’T do this with an external context file, ROOT.xml.

It won’t work. Instead, add this context to the Host node in the server.xml file.

Example snippet from my conf/server.xml:

<Host name="localhost"  appBase="webapps"
      unpackWARs="true" autoDeploy="true">
 
  <!-- SingleSignOn valve, share authentication between web applications
       Documentation at: /docs/config/valve.html -->
  <!--
  <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  -->
 
  <!-- Access log processes all example.
       Documentation at: /docs/config/valve.html
       Note: The pattern used is equivalent to using pattern="common" -->
  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
         prefix="localhost_access_log." suffix=".txt"
 
       pattern="%h %l %u %t &amp;quot;%r&amp;quot; %s %b" resolveHosts="false"/>
        
        
        
  <Context path="" docBase="home">
 
      <!-- Default set of monitored resources -->
      <WatchedResource>WEB-INF/web.xml</WatchedResource>
 
      <!-- Uncomment this to disable session persistence across Tomcat restarts -->
      <!--
      <Manager pathname="" />
      -->
 
      <!-- Uncomment this to enable Comet connection tacking (provides events
           on session expiration as well as webapp lifecycle) -->
      <!--
      <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
      -->
 
  </Context>    
 
</Host>

The diff is:

136a137,156
>               <Context path="" docBase="home">
>                       <!-- Default set of monitored resources -->
>                       <WatchedResource>WEB-INF/web.xml</WatchedResource>
>
>                       <!-- Uncomment this to disable session persistence across Tomcat restarts -->
>                       <!--
>                       <Manager pathname="" />
>                       -->
>                       <!-- Uncomment this to enable Comet connection tacking (provides events
>                                on session expiration as well as webapp lifecycle) -->
>                       <!--
>                       <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
>                       -->
>
>               </Context>

I hope this helps.

Note, before doing the above, please verify that this information is correct. Perhaps everyone is reading the Tomcat docs incorrectly or there really is a configuration discrepancy.

Updates
12Feb2011: Funny, if you make the above change and still leave the ROOT application folder in the webapps folder, you can not open the original ROOT at http://host:port/ROOT, even if you add another context node in host. I guess I still don’t grok Tomcat config.

posted @ 2014-08-25 17:39  princessd8251  阅读(407)  评论(0编辑  收藏  举报