Sbt Assembly Include Conf Files inside JAR

I am using the sbt build plugin to generate a JAR file and I have the following folder structure:

src
 -main
  -scala
  -resources
    -application.conf

      

Now that I do

sbt clean assembly

      

I can see in the released Jar file that the application.conf file is included. I have two questions:

  • Why is the inline application.conf not in the resources folder in the last jar, but rather at the top level as shown below (Jar content).

    -rw-r - r-- 1 joe staff 272B May 16 21:03 application.conf drwxr-xr-x 3 joe staff 102B May 16 21:03 com / -rw-rr-- 1 joe staff 187B March 4, 2016 library .properties drwxr-xr-x 3 joe staff 102B May 16 21:03 typafe /

  • How do I load this application.conf file by setting System.property? For example, I want to be able to load application.conf by setting the System property like:

    System.setProperty ("config.file", "application.default.conf")

With that, I could control externally (when running the jar file) which config file to use. When I tried this I got a NulPointerException:

val someConfigFile = Option(System.getProperty("config.file"))
ConfigFactory.parseURL(getClass.getResource(someConfigFile.get)) // NullPointerException happens here...

      

+3


source to share


2 answers


Here is what I need to do so that the config file inside the jar can be loaded based on what I specify from the outside!



  val is = new InputStreamReader(getClass.getResourceAsStream(s"/$cfgFile"))
  ConfigFactory.parseReader(is).resolve()

      

0


source


The answer to your first question is that the resources folder is like the src folder, so the contents are copied and not the folder itself.



0


source







All Articles