Thursday, October 10, 2013

Set the context path of a web application in Tomcat 7.0

Try to deploy a war package in Tomcat 7 with different web context path, at last it works with below steps:

1. Create context.xml file with your new context path name. For example:  mynewpath.xml

Don't just use default file name context.xml as your web file name, otherwise the Tomcat will deploy a new app with \context . But you want \mynewpath . It is a tricky.

In file you need to add:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="myapp.war"
  reloadable="true" path="/mynewpath"/>

2. Put this mynewpath.xml in Tomcat\conf\Catalina\localhost.
3. Deploy your war file outside the webapp folder like below:

C:\apache-tomcat-7.0.42\myapp.war


That's it.