开发者

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

开发者 https://www.devze.com 2022-12-17 07:49 出处:网络
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.I

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, an开发者_如何学God based on convention the web app will know where to read the file. What's the best practice in this case?


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.


I was also facing the same problem in the project. The developer before me had done crude fix for the solution which was adding all the required configuration in the hibernate.hbm.cfg.xml file and commenting them. The required configurations were uncommented as per the need. There is a better solution to problem however.

  1. Use a configuration folder schema
  2. Using configuration Parameter Reader
  3. Use of ConfigurationReader component

Source : http://www.javaworld.com/javaworld/jw-11-2004/jw-1108-config.html

0

精彩评论

暂无评论...
验证码 换一张
取 消