• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Versioned (changing) .war file name

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic