Tomcat 7 change ROOT application

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 &quot;%r&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.

Links


Ralph Towner — Green and Golden

About these ads

8 Responses to Tomcat 7 change ROOT application

  1. Sudheer says:


    WEB-INF/web.xml


    WEB-INF/web.xml

    With above change, i’m able to access myAPP at / and ROOT at /ROOT

  2. a says:

    You can rename root app fnd access to it for example at lovalhost/ROOT1

  3. archmisha says:

    I am using a different way:
    In webapps\ROOT I create index.html that contains:

    • Massimo says:

      Hi,
      I can’t see the content of the index.html that your’re using to force the default ROOT application in the post. Could you please resend it to me ?
      thank you
      Massimo

  4. jackgzhang says:

    good. It saves me a lot of time.

  5. Nasr says:

    Hi All,

    I have tried adding the context in the server.xml for my application. Restarted the tomcat and now the application is not loading. Is there any other change??

  6. josefB says:

    Hmmm. I can get to the manager with the same url. Is it prompting for a password?

  7. Mick Smith says:

    Nice tutorial, it works! However, once I have made my own app the root app. I am having problem accessing the manager app with tomcat 7.0.11

    When I try to go to the url:
    http://localhost:8080/manager
    I get a 403 Access Denied Error.

    How can I access the manager app when it is not the root?

    I tried removing the CSRF filter & filter mapping in the web.xml but that didnt work.

    Thanks for your help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: