Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the context path of a web application in Tomcat 7.0

People also ask

How do I change the context path of a web application?

To change the context root of a web application that is already available in the Eclipse workspace, simply right-click on the web project and call the “Properties” action from the context menu.

How do you set context root for web application?

A context root identifies a web application in a Java EE server. You specify the context root when you deploy a web module. A context root must start with a forward slash (/) and end with a string.

Where is Tomcat context path?

The context path refers to the location relative to the server's address which represents the name of the web application. By default, Tomcat derives it from the name of the deployed war-file. So if we deploy a file ExampleApp. war, it will be available at http://localhost:8080/ExampleApp.


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!


This is the the only solution that worked for me. Add the following to the Host node in the conf/server.xml file.

<Context path="" docBase="yourAppContextName">
 
  <!-- Default set of monitored resources -->
  <WatchedResource>WEB-INF/web.xml</WatchedResource>

</Context>

In Tomcat 9.0, I only have to change the following in the server.xml

<Context docBase="web" path="/web" reloadable="true" source="org.eclipse.jst.jee.server:web"/>

to

<Context docBase="web" path="" reloadable="true" source="org.eclipse.jst.jee.server:web"/>

This little code worked for me, using virtual hosts

<Host name="my.host.name" >
   <Context path="" docBase="/path/to/myapp.war"/>
</Host>

Quickest and may be the best solution is to have below content in <TOMCAT_INSTALL_DIR>/conf/Catalina/localhost/ROOT.xml

<Context 
  docBase="/your_webapp_location_directory" 
  path="" 
  reloadable="true" 
/>

And your webapp will be available at http://<host>:<port>/


It's not recommended to update the server configuration like server.xml or ROOT.xml.

You can put a context.xml configuration file under your web-application META-INF directory, with the context path setting included. This will override the default server setting?

i.e.:

<Context docBase="yourAppName" path="/yourAppPath" reloadable="true">