0

My application WAR has some settings baked in already. I would like to change them on fly before deploying in tomcat container. Right now I deploy them in /Catalina_base/, start the tomcat application, once WAR is uncompressed, I update conf file and restart tomcat. Any best practice to update conf file before starting tomcat ?

Also, how do I achieve this using chef cookbook?

Greatly appreciate your help.

Chucks
  • 899
  • 3
  • 13
  • 29
  • 1
    Best practice is to externalize any environment-specific configuration out of the war file. This former question describes some of the options for externalizing. http://stackoverflow.com/questions/13956651/externalizing-tomcat-webapp-config-from-war-file – Chris Nauroth Dec 30 '15 at 21:14

1 Answers1

0

As the comment from Chris Nauroth says, best practice is to keep environment-specific configuration out of the WAR.

However if you are stuck with the configuration being in that WAR, then you can use zip tools to update the configuration file.

If you are on a typical Linux distribution, then assuming your WAR file is called application.war and the configuration file you want to update is WEB-INF/classes/com/example/config.properties then you can run these commands during your deployment before you start Tomcat:

unzip application.war WEB-INF/classes/com/example/config.properties
# edit the configuration file now
zip -f -m application.war WEB-INF/classes/com/example/config.properties

After the unzip command, the file will be in a subfolder matching its location in the WAR (eg WEB-INF/classes/com/example/config.properties) and then the second zip command will delete it from the disk and put it back into the WAR.

I'm not familiar with Chef so I'm not sure how to run those commands automatically as part of the deployment, but presumably it provides a way to run command directly like this.

gutch
  • 6,959
  • 3
  • 36
  • 53