- Details
- Written by Nam Ha Minh
- Last Updated on 06 August 2019   |   Print Email
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- 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!
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:
Nam Ha Minh 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.