0
votes

I'm using the sbt assembly jar plugin to create a standalone jar file. My project folder structure would look like this:

MyProject
 -src
   - main
     - scala
       - mypackages and source files
     - conf // contains application.conf, application.test.conf and so on
   - test
 -project // contains all the build related files
 - README.md

I now want to be able to run the fat jar that I produce against a version of the application.conf that I specify as a System property!

So here is what I do in my unit test!

System.setProperty("environment", "test")

And this is how I load the config in one of the files in my src folder:

val someEnv = Option(System.getProperty("environment", "")).filter(_.nonEmpty) // gives me some(test)
val name = s"application.${someEnv.get}.conf" 

I can see that the environment variable is set and I get the environment passed it. But later on I load the application.test.conf as below:

ConfigFactory.load(name).resolve()

It however loads just the edfault application.conf and not the one that I specify!

What is wrong in my case? Where should I put the conf folder? I'm trying to run it against my unit test which is inside the test folder!

2
Is it really src/main/mypackages and src/main/conf? Shouldn't it be src/main/scala/mypackages and src/main/resources/ ?mfirry
Sorry about that! Good catch!joesan
But that was not causing the actual problemjoesan
not even src/main/resources ?mfirry

2 Answers

0
votes

I believe you need to specify the full name of the configuration file. The .conf is optional. Try

ConfigFactory.load(s"application.${someEnv.get}").resolve()

The docs for ConfigFactory.load(String) indicate you need to supply

name (optionally without extension) of a resource on classpath

0
votes

Ok! Here is what I had to do! Change the name of the folder where the config file is located. I originally had it as conf and I had to rename it to resources and bang it worked!