Typesafe config: Load additional config from path external to packaged scala application

ScalaConfigurationApp ConfigConfigTypesafe Stack

Scala Problem Overview


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")

Scala Solutions


Solution 1 - Scala

I think what you want is:

val myCfg =  ConfigFactory.parseFile(new File("my_path/hdfs.conf"))

Solution 2 - Scala

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

Solution 3 - Scala

val config = ConfigFactory.load("pathtoFile/FileName.propertes") 

works, too.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRAbrahamView Question on Stackoverflow
Solution 1 - ScalacmbaxterView Answer on Stackoverflow
Solution 2 - ScalatcatView Answer on Stackoverflow
Solution 3 - ScalaSureshView Answer on Stackoverflow