You need to rename ROOT.xml to myapp.xml with following content,
<Context docBase="/catalina_home/webapps/ROOT.war" />
By doing this, you create 2 contexts "/" and "/myapp" sharing the same WAR file.
If you just want to have one webapp, the easiest thing to do is to rename ROOT.war into myapp.war.
What you can do is the following;
Add a file called ROOT.xml
in <catalina_home>/conf/Catalina/localhost/
This ROOT.xml will override the default settings for the root context of the tomcat installation for that engine and host (Catalina and localhost).
Enter the following to the ROOT.xml file;
<Context
docBase="<yourApp>"
path=""
reloadable="true"
/>
Here, <yourApp>
is the name of, well, your app.. :)
And there you go, your application is now the default application and will show up on http://localhost:8080
However, there is one side effect; your application will be loaded twice. Once for localhost:8080
and once for localhost:8080/yourApp
. To fix this you can put your application OUTSIDE <catalina_home>/webapps
and use a relative or absolute path in the ROOT.xml's docBase tag. Something like this;
<Context
docBase="/opt/mywebapps/<yourApp>"
path=""
reloadable="true"
/>
And then it should be all OK!
Best Solution
There are three methods:
First shutdown your Tomcat from the its
bin
directory (sh shutdown.sh
). Then delete all the content of your Tomcatwebapps
folder (rm -fr *
). Then rename your WAR file toROOT.war
, and finally start your Tomcat from thebin
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 theserver.xml
file. Explicitly define all application Contexts inserver.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 theserver.xml
.Place your WAR file outside of
$CATALINA_BASE/webapps
(it must be outside to prevent double deployment). Place a context file namedROOT.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 caseROOT.xml
. See the documentation for the Context container for details.Reference