2

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.

Aldrin Rodrigues
  • 151
  • 1
  • 11

2 Answers2

2

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

Cédric Couralet
  • 4,913
  • 1
  • 21
  • 21
0

Had a similar problem and it took me a long time to find the solution. It's on the tomcat site but it's difficult to find. This is what I did.

Your war file will be deployed to a folder under %CATALINA_BASE%. I put mine in a folder called deploy. (%CATALINA_BASE%/deploy)

You'll create an XML file with the path to your war file above and place it in %CATALINA_BASE%/conf/Catalina/localhost. The name of the xml file will become your context root. If the name of your war file is app1.2.war and you want your context root to be /app you're create app.xml: <?xml version='1.0' encoding='utf-8'?> <Context docBase="C:\tomcat7\Servers\server-app\deploy\app1.2" reloadable="false"/> (My deployment is on Windows, you'll obviously have to adjust for a different OS.)

Also, let's for whatever reason say you want your context root to be /foo/Bar/app, change the name of your xml to foo#Bar#app.xml.

Striker
  • 339
  • 1
  • 3
  • 13