a.moussa a.moussa - 3 years ago 89
Scala Question

read a scala conf file from a maven jar

I would like to read two scala conf file from a maven jar named myconfiguration1.conf and myconfiguration2.conf:

driver= oracle.jdbc.driver.OracleDriver
user = myUser
password = pass
url = myUrl
table = my_table


before generate my jar, i used a line like this:

val myconfig1 = ConfigFactory.parseFile(new File("./my-project/src/main/resources/myconfiguration1.conf"))
val myconfig2 = ConfigFactory.parseFile(new File("./my-project/src/main/resources/myconfiguration2.conf"))


Inside my jar, i have a tree like this

my-project-0.0.1.jar
|___ myconfiguration1.conf
|___ myconfiguration2.conf


Do you have any idea since the two lines don't work with the jar file.

Answer Source

Seems you are using typesafe config to load the conf file, you can directly use ConfigFactory.load("myconfiguration1.conf") and ConfigFactory.load("myconfiguration2.conf") to load the classpath configuration file.

public static load(java.lang.String resourceBasename)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download