Best practice for setting environment settings for a Java web application?

I have a Java web application that unloads some environment parameters (Hibernate configurations, necessary directory paths, etc.) in a properties file that is ultimately packaged in a deployed WAR. If I want to distribute this web application, what is the best way to handle these settings? It is not possible to ask the user to open a WAR, update the properties file, repackage the WAR, and then deploy. I was thinking of creating an installer (e.g. NSIS, WiX) that requests properties, writes them to the WAR, and then requests the deployment location for the WAR. Another option is to have a properties file external to the WAR, and based on the agreement, the web application will know where to read the file. What is the best practice in this case?

+3
source share
2 answers

Some projects that require this configuration and encounter this problem take the approach of creating projects (and .war) on the server where it will be deployed.

So, instead of:

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

You get:

  • Check out the source code from SCM (Subversion, CVS, etc.).
  • Taste
  • Build a project (automated using Maven or Ant)
  • Deploy a project (also usually automated using Maven or Ant)

From here you can get fancy by checking every server configuration file in SCM. This approach allows you to modify and modify the configuration of the configuration.

+1
source

. , hibernate.hbm.cfg.xml . . .

  • ConfigurationReader

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

0

Source: https://habr.com/ru/post/1729460/


All Articles