Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default application in tomcat 7

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.

like image 545
Manish Mulani Avatar asked Jan 14 '13 19:01

Manish Mulani


People also ask

What is docBase in Tomcat?

The docBase attribute is a path to the WAR file or exploded deployment directory. It is relative to the webapps directory, although an absolute path can be used. The path attribute is the one we are most interested in, as it defines the context path of the application.


1 Answers

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.

like image 86
TheWhiteRabbit Avatar answered Sep 20 '22 23:09

TheWhiteRabbit