53

My scala application will be packaged into a jar. When I run my app, it needs to read an additional config file stored externally to my app jar. I am looking for functionality similar to the Typesafe Config library but other solutions are welcome too ! Is there a way to do something like below:

val hdfsConfig = ConfigFactory.load("my_path/hdfs.conf")
RAbraham
  • 5,956
  • 8
  • 45
  • 80

3 Answers3

74

I think what you want is:

val myCfg =  ConfigFactory.parseFile(new File("my_path/hdfs.conf"))
cmbaxter
  • 35,283
  • 4
  • 86
  • 95
17

If your external configuration is to add to or override configuration parameters from standard locations, you can do the following:

val baseConfig = ConfigFactory.load()
val config = ConfigFactory.parseFile(yourFile).withFallback(baseConfig)

where yourFile is a java.io.File Documentation reference here

tcat
  • 351
  • 3
  • 4
5
val config = ConfigFactory.load("pathtoFile/FileName.propertes") 

works, too.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Suresh
  • 38,717
  • 16
  • 62
  • 66