How to set context path in context.xml

Aldrin Rodrigues picture Aldrin Rodrigues · Apr 26, 2016 · Viewed 7.6k times · Source

I have to deploy my app.war file in tomcat 7. The .war file name is followed by its version no. Here I need to set up a context path, so that the actual url will contain only the app name(without version no).

My requirement is that, there should be no edit in server.xml.

My context.xml is as follows.

<?xml version='1.0' encoding='utf-8'?>
<Context path="/app" docBase="app-1.0" debug="0" reloadable="true">

    <!-- Defines links to JNDI Data Sources -->
    <!-- Thus the server determines database connection. -->

    <ResourceLink
            name="..."
            global="..."
            auth="Container" type="javax.sql.DataSource"/>

    .....
    .....

</Context>

The context.xml is placed inside the war at /META-INF folder. Can anyone tell me where am i wrong.

Answer

C&#233;dric Couralet picture Cédric Couralet · Apr 26, 2016

All the elements are in the docs : http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

For your use case, you could do try :

  • change your version number format (from app-1.0.0.war to app##1.0.0.war for instance)

  • place your war in another folder and create a app.xml in $catalina.base/conf/Catalina/ which contains : <Context path="/app" docBase="/path/to/app-1.0" debug="0" reloadable="true">

  • avoid having your war with version number