I have an application with a configuration file which has a lots of environment-specific settings. Also I have a bunch of environments where that application can be deployed.
What are the best practices of making that configuration environment-specific?
Currently I’m adding the directory where the config files are located to the JVM classpath. This way application simply loads the configuration files from the classpath and uses what it finds there.
However, recently I was told that this is a bad practice and that I should consider using JNDI for such purpose.
So, what could you recommend to make the deployment and development processes as painless as possible in my situation?
Thanks in advance.
You could allow users to specify the configuration file/directory with whichever of the following appeals to you: (1) a command-line argument; (2) a Java system property; or (3) an environment variable.
Note that you can access the
FOO_CONFIGenvironment variable by callingSystem.getenv("FOO_CONFIG"). Sun “deprecated” (a euphemism for deliberately broke) this operation between Java 1.0.1 and Java 1.4.x inclusive. However, this operation was undeprecated (that is, fixed) in Java 5.