15

I've gone through the threads that describe how to configure a given WAR (say abc.war) as default web-app in tomcat.

Either

Rename the abc.war to ROOT.war

or

Create a context ROOT.xml in ${tomcat.home}/conf/Catalina/localhost with path="" and docBase set to relative/absolute path to the war (keeping the abc.war outside of webapps to avoid double deployment).

Both the solutions result in ROOT.war in webapps (appBase) directory. However I want to retain the WAR name (abc.war) in webapps and not have a separate ROOT.war to achieve this.

One solution that worked in my case was adding a context under <Host> tag in server.xml . But as per Tomcat 7 Doc , it's not recommended to add context directly in server.xml.

Could someone point me to an alternative?

Thanks.

Manish Mulani
  • 7,125
  • 9
  • 43
  • 45

1 Answers1

20

detailed approach

First Method:

first shutdown your tomcat [from the bin directory (sh shutdown.sh)] then you must delete all the content of your tomcat webapps folder (rm -fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]

Second Method:

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 path and docBase. 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.

Note:

that this last method also implies that in order to make any change to any application, you will have to stop and restart Tomcat.

Third Method:

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 Context Container above for details.

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
  • 1
    Keep in mind, with the third method the war file will not deploy to the webapps folder, assuming you have kept the default in the server.xml. Also, if you have myApp.war and you want the context root to be /foo/bar you would name your xml file foo#bar.xml – Striker May 30 '13 at 01:16
  • 1
    I have tried your 3rd solution but it is not working for me. My app name is `springExample` i placed it under `C:\Tomcat\springExample.war` outside the webapps DIR as mentioned. And then i created a `ROOT.xml` file in `C:\Tomcat\conf\Catalina\localhost\ROOT.xml`.The content of ROOT.xml is ` `. And restarted the server .Please tell me where i am doing wrong. – Vaibhav Jain Dec 10 '13 at 08:30
  • 1
    I managed to made it work by changing the `docBase attribute value to ` . But can you tell me now where `Tomcat` is extracting this `war` file. And can it be managed through `Tomcat app manager web interface`.Thanks ... – Vaibhav Jain Dec 10 '13 at 08:41
  • It will be greatly more helpful if we can have setting example for the second and third solutions – JaskeyLam Oct 23 '15 at 07:49
  • 1
    Add an example for third method – Sumodh S Dec 03 '15 at 08:59
  • @SumodhS its self explanatory isnt it ? it'd be a far fetch to provide a complete example – TheWhiteRabbit Dec 04 '15 at 09:24