File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Versioned (changing) .war file name Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Reply Bookmark "Versioned (changing) .war file name" Watch "Versioned (changing) .war file name" New topic
Author

Versioned (changing) .war file name

Rex Chandler
Greenhorn

Joined: Mar 15, 2010
Posts: 2
Hello all,

We want to start versioning the name of one of our .war files. Before this, the .war always had the same name, so it was not a problem for our QA people to deploy it as foo.war mapped to /foo/doIt.

Now, we want to have .war file names like 1.0.1-foo.war. This of course will map to /1.0.1-foo/doIt. This clearly isn't what we want.

I've found a way to map a new context root to your war in the server.xml file:

<Context path="/foo" docBase="1.0.1-foo.war"/>

The problem is that the .war file specified in the docBase attribute changes with each build. Is there a way to 'genericize' the value? Maybe something like:

<Context path="/foo" docBase="*foo.war"/>

I'm lost at this point and any help would be very much appreciated.

Thanks,

Rex
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 469
Rex Chandler wrote:We want to start version the name of one of our .war files


Any good reasons for doing that?
Rex Chandler
Greenhorn

Joined: Mar 15, 2010
Posts: 2
Misha Ver wrote:
Rex Chandler wrote:We want to start version the name of one of our .war files


Any good reasons for doing that?


Good reason... not really.

Acceptable reason... because the person in charge told me to j/k Some of our clients change and upgrade slower than others. By having the version be part of the .war itself, we can tell at a glance what version someone is running in the event of an error. This is the easiest way to do things with the way our system is set up (vs. having a request that can be sent to the running code to get the version, looking at readme files, etc).

Rex
Jaikiran Pai
Saloon Keeper

Joined: Jul 20, 2005
Posts: 6564

Based on this documentation, all you have to do is package a META-INF/context.xml in your .war file with the following contents:



The docBase will be inferred by default (based on the .war file name). And you don't even have to edit the global server.xml.


[My Blog] [JavaRanch Journal]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 11740

Jaikiran Pai wrote:Based on this documentation, all you have to do is package a META-INF/context.xml in your .war file with the following contents:



The docBase will be inferred by default (based on the .war file name). And you don't even have to edit the global server.xml.



Yup. Or you can supply an external context file (in TOMCAT_HOME/conf/Catalina/localhost) that can provide the context and allow you to switch versions by simply changing the name of the codebase WAR file in that context file. Or you can deply using the Tomcat manager or similar deployment tool (which will create a context file for you).

I also like to put a "version.txt" file in my WARs to ensure that I can query the webapp and see if I'm running the version I think I'm running.

One caution, however. When redeploying, it's a good idea to remove the old contents of TOMCAT_HOME/work/Catalina/localhost and any exploded WARs from TOMCAT_HOME/webapps. Otherwise you can end up with stale code and resources.


A lot the of modern-day software development platforms are designed to permit parcelling out work to those with the best aptitude for it. A lot of modern-day business is predicated on making one person do all the work, regardless of aptitude.
 
 
subject: Versioned (changing) .war file name
 
MyEclipse, The Clear Choice