Tuesday, February 9, 2010

Tomcat 6 : howto make your app your default server app

Copied from WIKI:

How do I make my web application be the Tomcat default application ?


Congratulations. You have created and tested a first web application (traditionally called "mywebapp"), users can access it via the URL "http://myhost.company.com/mywebapp". You are very proud and satisfied. But now, how do you change the setup, so that "mywebapp" gets called when the user enters the URL "http://myhost.company.com" ?
The pages and code of your "mywebapp" application currently reside in (CATALINA_BASE)/webapps/mywebapp/. In a standard Tomcat installation, you will notice that under the same directory (CATALINA_BASE)/webapps/, there is a directory called ROOT (the capitals are important, even under Windows). That is the residence of the current Tomcat default application, the one that is called right now when a user calls up "http://myhost.company.com[:port]". The trick is to put your application in it's place.
First stop Tomcat.
Then before you replace the current default application, it may be a good idea to make a copy of it somewhere else.
Then delete everything under the ROOT directory, and move everything that was previously under the (CATALINA_BASE)/webapps/mywebapp/ directory, toward this (CATALINA_BASE)/webapps/ROOT directory. In other words, what was previously .../mywebapp/WEB-INF should now be .../ROOT/WEB-INF (and not .../ROOT/mywebapp/WEB-INF).
Just by doing this, you have already made you webapp into the Tomcat default webapp.
One step is left : you also need to have, within your application, a default servlet. This, you do by means of an appropriate url-mapping in the WEB-INF/web.xml configuration file of your application. Make sure you have something like this in that file :

    # 
    #    My First Servlet
    #   my.Servlet.Number1
    #

    #
    #   My First Servlet
    #    /*
    # 
 
Restart Tomcat and you're done.
Call up "http://myhost.company.com/" and enjoy.