4

From what I have read the typesafe config library reads from the classpath or system variables. This doesn't work very well for me because passing many arguments on the command line is not feasible and I don't want our devops team to have to rebuild the jars just to change a setting. They're also not too happy about setting loads of environment variables.

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

Ideally I would it to look in the ~/.ourapp.conf file first, then look for environment variables and finally fallback to application.conf and reference.conf.

lospejos
  • 1,888
  • 3
  • 17
  • 31

2 Answers2

5

Apart form specifiying a acommand line parameter: -Dconfig.file=, you could do it in the 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)
Sascha Kolberg
  • 6,716
  • 1
  • 30
  • 36
3

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

ffxtian
  • 549
  • 2
  • 5
  • Perfect, I'm going to test this and see if it works for other typesafe config based apps (we're building a spray/akka app now) –  Jul 22 '15 at 18:18