Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for handling environment specific settings for a Java web app?

I have a Java web app that offloads some environment specific settings (Hibernate configurations, required directory paths, etc.) in a properties file that is ultimately packaged in the deployed WAR. If I wish to distribute this web app, what's the best way to handle the mangement of these settings? It's not feasible to ask the user to open up the WAR, update the properties file, repackage the WAR, and then deploy. I was thinking of either creating an installer (e.g. NSIS, WiX) that asks for the properties, writes them in the WAR, and then asks for the deployment location for the WAR. The other option is to have the properties file external to the WAR, and based on convention the web app will know where to read the file. What's the best practice in this case?

like image 898
mshafrir Avatar asked Dec 10 '25 15:12

mshafrir


1 Answers

Some projects that require this sort of configuration, and face this issue, use the approach of building the projects (and the .war) on the server where it will be deployed.

So instead of:

  • Copy a pre-packaged .war file to a meaningful location

You get:

  • Check source code out of SCM (Subversion, CVS, etc.)
  • Configure to taste
  • Build the project (automated with Maven or Ant)
  • Deploy the project (also typically automated using Maven or Ant)

From here you can get fancy by checking each server's configuration files into SCM as well. This approach allows you to version & audit configuration changes.

like image 99
Drew Wills Avatar answered Dec 13 '25 18:12

Drew Wills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!