Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the ROOT application?

Tags:

tomcat

tomcat6

People also ask

Where is the root directory in Tomcat?

Tomcat Deployment Basics and Terminology Simply put, web applications are placed under $CATALINA_HOME\webapps, where $CATALINA_HOME is the Tomcat's installation directory.

What is context root in Tomcat?

The context path of a web application defines the URL that end users will access the application from. A simple context path like myapp means the web app can be accessed from a URL like http://localhost:8080/myapp.


There are three methods:

  • First shutdown your Tomcat from the its bin directory (sh shutdown.sh). Then delete all the content of your Tomcat webapps folder (rm -fr *). Then rename your WAR file to ROOT.war, and finally start your Tomcat from the bin directory (sh startup.sh).

  • Leave your war file in $CATALINA_BASE/webapps under its original name. Turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. Explicitly define all application Contexts in server.xml, specifying both the path and docBase attributes. You must do this because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml.

    second method: in order to make any change to any application, you will have to stop and restart Tomcat.

  • Place your WAR file outside of $CATALINA_BASE/webapps (it must be outside to prevent double deployment). Place a context file named ROOT.xml in $CATALINA_BASE/conf/. The single element in this context file MUST have a docBase attribute pointing to the location of your WAR file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the documentation for the Context container for details.

Reference


In Tomcat 7 with these changes, i'm able to access myAPP at / and ROOT at /ROOT

<Context path="" docBase="myAPP"/>
<Context path="ROOT" docBase="ROOT"/>

Add above to the <Host> section in server.xml


Adding a <Context> tag in the <Host> tag in server.xml for Tomcat 6 will resolve the problem.

If you use path="" empty you can use a URL like http://localhost/first.do.

In the context tag set attributes docBase="E:\struts-ITRCbook\myStrutsbook" and reloadable="true", then end the context tag.

It should look something like this:

<Host name="localhost"  appBase="webapps" 
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">
    <Context path="" docBase="E:\struts-ITRCbook\myStrutsbook" reloadable="true">
    </Context>
</Host>

ROOT default app is usually Tomcat Manager - which can be useful so I felt like keeping it around.

So the way i made my app ROOT and kept TCmgr was like this.

renamed ROOT to something else

mv ROOT TCmgr

then created a symbolic link whereby ROOT points to the app i want to make the default.

ln -s <your app> ROOT

worked for me and seemed the easiest approach.


According to the Apache Tomcat docs, you can change the application by creating a ROOT.xml file. See this for more info:

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

"The default web application may be defined by using a file called ROOT.xml."


You can do this in a slightly hack-y way by:

  1. Stop Tomcat
  2. Move ROOT.war aside and rm -rf webapps/ROOT
  3. Copy the webapp you want to webapps/ROOT.war
  4. Start Tomcat