Sunday, July 25, 2010

Tomcat: How to add user defined context path to access an application

In tomcat (5.x and above), the context path of an application defaults to application name where application war file is exploded. For example if application is named examples (ex: located in webapps/examples) then by default url to access is: http://localhost:8080/examples/ (assuming you have deployed to localhost)

Specifying one or more additional context path to map to the same application:

To specify additional path to access an application, we need to add <Context> element under conf/server.xml like below:

<Context path="/api/examples" docBase="examples">


<!-- Default set of monitored resources -->


<WatchedResource>WEB-INF/web.xml</WatchedResource>


</Context>

With above we defined a new path "/api/examples" to access the same examples application as specified in docBase. So now examples application can also be accessed as: http://localhost:8080/api/examples/

For more information about context configuration check out tomcat context documentation.
Promote your blog

No comments:

Post a Comment