Configafe configuration file in home directory

From what I've read, the configafe type library reads from the classpath or system variables. This doesn't work very well for me because passing many command line arguments is not possible and I don't want our detonation team to have to rebuild the jars just to change the setting. They are also not too happy with setting loads of environment variables.

Is it possible to specify an external file that is not on the classpath, similar to how Spring works?

Ideally, I would first look in the ~ / .ourapp.conf file, then look at the environment variables, and finally override the application.conf and reference.conf.

+3


source to share


2 answers


A separate form specifying the acommand: line parameter -Dconfig.file=

, you can do it in code with something like this:



val defaults = ConfigFactory.load()
val file = new File("~/path/custom.config")
// I'm not sure what you mean with environment variables, 
// but you could read environment variables into a map and then use 
val env = ConfigFactory.parseMap(envMap)
val settings = ConfigFactory.parseFile(file).withFallBack(env).withFallBack(defaults)

      

+5


source


You can specify -Dconfig.file = ~ / .ourapp.conf on the command line behind https://www.playframework.com/documentation/2.0/ProductionConfiguration



+3


source







All Articles