In this article, we'll guide you how to configure Tomcat server to specify the server's context root is also the context path of a web application. In other words, you will learn how to deploy a Java web application which can be accessed via server's context root - or hostname.

By default, when you deploy a Java web application on Apache Tomcat server, the website can be accessed through this kind of URL :

http://hostname:port/WebAppName/
Here, the context root of the server is hostname, and the context path of the web applicaton is WebAppName.

However, in practice we may want to use only the server's host name to access the web application, via this kind of URL:

http://hostname:port/
In this case the context path of the web application is united with the server root - it would be very convenient for many cases. So, how to setup Tomcat server to change the default?

The simplest way is to deploy your Java web application as ROOT.war under the webapps directory.

 

Follow these steps:

- Rename your web application's WAR file to ROOT.war



- Make sure the server is stopped.

- Navigate to the webapps directory under Tomcat installation location. This is the base directory of localhost, where Java applications are deployed to.

- Inside webapps, you can see the 3 folders installed by default: docs, manager, and ROOT. docs contains Tomcat documentation; manager is the Tomcat manager application; and ROOT contains welcome pages you see when accessing the server's context root at http://localhost

TomcatROOT

- Rename or delete the default ROOT directory.

- Copy your ROOT.war file to webapps directory.

- Start Tomcat, and you will see it extracts your ROOT.war file to deploy your web application.

- Now your web application can be accessed via server hostname (or its context root). Enjoy!

 

WebAppRoot 

 

NOTES:

You can still access Tomcat manager application with the context path /manager.

Apply the same steps in case you use virtual host with different base directory.

 

Other Tomcat Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment

   


Comments 

#3Mohd danish2022-12-07 04:02
it worked but the thing is when i make any changes to my source code with the help of CI/CD pipeline those changes doesn't reflect on my application ...
Quote
#2Jay2020-05-07 16:06
This is great. But if I have a virtual host configured, created mynewdomainapps folder and set it as appBase. I placed a simple index.html in the folder but my domain is still rendering the default host. I want to keep the default host as is and have a virtual host to handle the "mynewdomain.com" for example. Failing to get it right.
Quote
#1Abhishek2019-11-10 23:21
it is not working for me
Quote