I have the war file of my application. I need to deploy this at the root level. The current URL is http://localhost:8080/war_name/application_name
.

- 10,148
- 7
- 57
- 107

- 4,714
- 10
- 33
- 46
-
1Could you please specify what exactly is your problem? When you a deploy a war file in tomcat, the application is accessed using URL : http://localhost:8080/war_name without the .war extension. – ajm Mar 16 '11 at 16:38
-
1Yes you are right, i need to access my app. "http://localhost/application_name", this i can acheive when i am renaming my war file to "ROOT.war", but its throwing out of memory exception because my war file size is around 120MB – iamjustcoder Mar 16 '11 at 16:41
-
1@user661660 - It seems like you have a different problem - renaming to `ROOT.war` should work. I would suggest asking another question about your `OutOfMemoryException`, providing the stack trace and the details. You can probably get around it by configuring `-Xmx` for the JVM. – Rob Hruska Mar 16 '11 at 16:48
-
.lang.OutOfMemoryError: PermGen space Mar 16, 2011 9:52:52 AM com.ebay.kernel.logger.Logger log SEVERE: Error in Perfmon thread java.lang.OutOfMemoryError: PermGen space Exception in thread "CalClient:NotifyThreadDestroyThread-0" java.lang.OutOfMemor yError: PermGen space Exception in thread "MetricsSnapshotScheduler" java.lang.OutOfMemoryError: PermG en space Mar 16, 2011 9:53:36 AM com.ebay.kernel.logger.Logger log SEVERE: Error in Perfmon thread java.lang.OutOfMemoryError: PermGen space Exception in thread "CalClient:NotifyThreadDestroyThread-0" java.lang.OutOfMemor yError: PermGen space – iamjustcoder Mar 16 '11 at 17:00
-
1@user661660 - Perhaps some of the [answers for this question](http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error) can help you. – Rob Hruska Mar 16 '11 at 17:02
-
You would want to look into this [http://stackoverflow.com/questions/715506/tomcat-6-how-to-change-the-root-application][1] [1]: http://stackoverflow.com/questions/715506/tomcat-6-how-to-change-the-root-application – abbas Jun 10 '13 at 15:40
10 Answers
You have a couple of options:
Remove the out-of-the-box
ROOT/
directory from tomcat and rename your war file toROOT.war
before deploying it.Deploy your war as (from your example)
war_name.war
and configure the context root inconf/server.xml
to use your war file :<Context path="" docBase="war_name" debug="0" reloadable="true"></Context>
The first one is easier, but a little more kludgy. The second one is probably the more elegant way to do it.

- 6,082
- 3
- 33
- 49

- 118,520
- 32
- 167
- 192
-
3If Tomcat is set to autodeploy, you don't have to worry about option 2. – Buhake Sindi Mar 16 '11 at 16:54
-
1@Hruska Thanks for your suggestion After chaning, i am getting below exception SEVERE: Error in Perfmon thread java.lang.OutOfMemoryError: PermGen space Exception in thread "CalClient:NotifyThreadDestroyThread-0" java.lang.OutOfMemor yError: PermGen space May be i need to increase the JVM memory, do you have any idea about this? – iamjustcoder Mar 16 '11 at 16:58
-
1@user661660 - Perhaps some of the [answers for this question](http://stackoverflow.com/questions/88235/how-to-deal-with-java-lang-outofmemoryerror-permgen-space-error) can help you. – Rob Hruska Mar 16 '11 at 17:00
-
Do you know how to do the same thing in Glassfish? I don't want show the port number in my app, but I have no idea about it. – Marco Paulo Ollivier May 30 '14 at 19:03
-
I haven't used Glassfish, so I'm not sure. If you don't want the port to show in browsers, you'll want to host it on `:80`. Not sure if [this](http://alexismp.wordpress.com/2007/08/30/glassfish-tip-have-your-application-be-the-root-application/) helps on making it the root app or not. – Rob Hruska May 31 '14 at 01:29
-
1
-
4@Dejel - Nothing technically. I've done it quite a bit myself; it gets the job done. Just feels a bit wonky to have to rename your own war file to something that's kind of an implementation detail of the container. – Rob Hruska Jan 15 '15 at 18:43
-
something interesting - I followed 2, and I have inside in server.xml
WEB-INF/web.xml -
@nishant either put `myApp.war` somewhere outside of the `webapps` dir so it doesn't autodeploy, or disable its autodeploy with an extra context entry like `
` – Nick Mar 09 '15 at 12:42 -
6As per link you provided **It is NOT recommended to place
elements directly in the server.xml file** – Nilesh Mar 23 '16 at 07:36 -
6This answer recommends a technique that is explicitly mentioned in the documentation as bad form. The proper technique is detailed here: http://stackoverflow.com/questions/41263245/how-to-deploy-apps-in-tomcat-server/41284328#41284328 – Christopher Schultz Dec 22 '16 at 13:33
-
@Dejell You should probably ask another question about that, but the answer is that you've deployed the application twice. Ponder your configuration and you'll eventually figure out why. Hint: where is your source WAR file located? – Christopher Schultz Dec 22 '16 at 13:35
-
5+1 for calling it ROOT.war. According to the Tomcat docs, you need to be very careful when specifying "path" to avoid double deploy: "Even when statically defining a Context in server.xml, this attribute must not be set unless either the docBase is not located under the Host's appBase or both deployOnStartup and autoDeploy are false. If this rule is not followed, double deployment is likely to result." - from http://tomcat.apache.org/tomcat-8.0-doc/config/context.html – Anthony Hayward Jan 10 '17 at 17:26
on tomcat v.7 (vanilla installation)
in your conf/server.xml add the following bit towards the end of the file, just before the </Host>
closing tag:
<Context path="" docBase="app_name">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
Note that docBase attribute. It's the important bit. You either make sure you've deployed app_name before you change your root web app, or just copy your unpacked webapp (app_name) into your tomcat's webapps folder. Startup, visit root, see your app_name there!

- 20,434
- 21
- 120
- 152
In tomcat 7 with these changes, i'm able to access myAPP at / and ROOT at /ROOT
<Context path="" docBase="myAPP">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="ROOT" docBase="ROOT">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
Add above to the <Host>
section in server.xml

- 2,499
- 2
- 23
- 28
-
3A context path must either be an empty string or start with a '/'. The path [ROOT] does not meet these criteria and has been changed to [/ROOT] – Nikita Bosik Apr 01 '15 at 00:59
I know that my answer is kind of overlapping with some of the other answer, but this is a complete solution that has some advantages. This works on Tomcat 8:
- The main application is served from the root
- The deployment of war files through the web interface is maintained.
- The main application will run on port 80 while only the admins have access to the managment folders (I realize that *nix systems require superuser for binding to 80, but on windows this is not an issue).
This means that you only have to restart the tomcat once, and after updated war files can be deployed without a problem.
Step 1: In the server.xml file, find the connector entry and replace it with:
<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector
port="80"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Step 2:
Define contexts within the <Host ...>
tag:
<Context path="/" docBase="CAS">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/ROOT" docBase="ROOT">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/manager" docBase="manager" privileged="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/host-manager" docBase="host-manager" privileged="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
Note that I addressed all apps in the webapp folder. The first effectively switch the root and the main app from position. ROOT is now on http://example.com/ROOT
and the the main application is on http://example.com/
. The webapps that are password protected require the privileged="true"
attribute.
When you deploy a CAS.war file that matches with the root (<Context path="/" docBase="CAS">
you have to reload that one in the admin panel as it does not refresh with the deployment.
Do not include the <Context path="/CAS" docBase="CAS">
in your contexts as it disables the manager option to deploy war files. This means that you can access the app in two ways: http://example.com/
and http://example.com/APP/
Step 3:
In order to prevent unwanted access to the root and manager folder, add a valve
to those context tags like this:
<Context path="/manager" docBase="manager" privileged="true">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
addConnectorPort="true"
allow="143\.21\.2\.\d+;8080|127\.0\.0\.1;8080|::1;8080|0:0:0:0:0:0:0:1;8080"/>
</Context>
This essentially limits access to the admin web app folder to people from my own domain (fake IP address) and localhost when they use the default port 8080 and maintains the ability to dynamically deploy the war files through the web interface.
If you want to use this for multiple apps that are using different IP addresses, you can add the IP address to the connector (address="143.21.2.1"
).
If you want to run multiple web apps from the root, you can duplicate the Service tag (use a different name for the second) and change the docbase of the <Context path="/" docBase="CAS">
to for example <Context path="/" docBase="ICR">
.

- 587
- 8
- 19
Remove $CATALINA_HOME/webapps/ROOT
. Update $CATALINA_HOME/conf/server.xml
, make sure that Host element look like the following text:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false">
<Context path="" docBase="myApp"></Context>
It works with Tomcat 8. autoDeploy and deployOnStartup need to set to false to prevent tomcat from deploying myApp
twice.

- 7,320
- 6
- 50
- 63
-
I tried uploading the WAR and it failed to work. Is this only for exploded WARs? – logixplayer Jul 15 '15 at 08:06
-
I tried uploading the WAR and it failed to work based on @Jingguo's example. Is this only for exploded WARs? EDIT: It is indeed ONLY for exploded wars. Why is this? Can I not just upload the WAR and avoid this double step? How can I make it work? – logixplayer Jul 15 '15 at 08:14
-
@logixplayer. My solution works with WAR. I did not explode it. I forgot to mention that `$CATALINA_HOME/webapps/ROOT` needs to be removed. Please remove it and try again. – Jingguo Yao Jul 17 '15 at 06:16
-
I removed the ROOT as you said. I deployed my WAR (not exploded directory). I noticed a new ROOT directory was created with my stuff in it e.g. WEB-INF. The site is running. Is this the way it's supposed to work? – logixplayer Jul 20 '15 at 06:25
-
I also tried this method and all when I try to open the page in browser it just keeps waiting for server. The catalina.out only says the server was started. – Asu Jul 23 '15 at 10:39
The fastest way.
Make sure you don't have ROOT app deployed, undeploy if you have one
Rename your war to ROOT.war, deploy, thats all, no configuration changes needed

- 3,238
- 22
- 36

- 1,045
- 14
- 23
Adding on to @Rob Hruska's sol, this setting in server.xml inside section works:
<Context path="" docBase="gateway" reloadable="true" override="true"> </Context>
Note: override="true" might be required in some cases.

- 303
- 1
- 4
- 15
-
you didn't mention where to put this. @Sudheer Palyam answer was helpful. – Kannan Ramamoorthy Jul 05 '17 at 12:31
open tomact manager url :- http://localhost:8080/manager/html/
then in applications you see a application having path as "/" is deployed
simply Undeploy this.
Rename your application's war file as ROOT.war and just place at path :-
C:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps
start your Tomcat No extra configuration needed.
Now we can see our application home page or configured url at http://localhost:8080

- 1,390
- 2
- 22
- 36
In my server I am using this and root autodeploy works just fine:
<Host name="mysite" autoDeploy="true" appBase="webapps" unpackWARs="true" deployOnStartup="true">
<Alias>www.mysite.com</Alias>
<Valve className="org.apache.catalina.valves.RemoteIpValve" protocolHeader="X-Forwarded-Proto"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="mysite_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b"/>
<Context path="/mysite" docBase="mysite" reloadable="true"/>
</Host>

- 3,675
- 3
- 34
- 37