【发布时间】:2017-10-16 00:39:07
【问题描述】:
我正在使用 sbt 程序集插件来创建一个 JAR 文件,并且我有以下文件夹结构:
src
-main
-scala
-resources
-application.conf
现在,当我这样做时
sbt clean assembly
我可以在生成的 Jar 文件中看到 application.conf 文件包含在内。我有两个问题:
-
为什么最终Jar的resources文件夹中没有包含application.conf,而是在顶层如下图(Jar的内容)
drwxr-xr-x 3 joe staff 102B May 16 21:03 com/ -rw-r--r-- 1 joe staff 187B Mar 4 2016 library.properties drwxr-xr-x 3 joe staff 102B May 16 21:03 typesafe/ -
如何通过设置 System.property 来加载这个 application.conf?例如,我希望能够通过设置如下系统属性来加载 application.conf:
System.setProperty("config.file", "application.default.conf")
有了这个,我可以从外部(在运行 jar 文件时)控制要使用的配置文件。当我尝试这个时,我得到了 NulPointerException:
val someConfigFile = Option(System.getProperty("config.file"))
ConfigFactory.parseURL(getClass.getResource(someConfigFile.get)) // NullPointerException happens here...
【问题讨论】:
标签: scala jar sbt-assembly