带有conf文件夹的Scala独立JAR [英] Scala Standalone JAR with a conf Folder
问题描述
我正在使用sbt汇编jar插件创建一个独立的jar文件.我的项目文件夹结构如下所示:
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
现在,我希望能够针对我指定为System属性的application.conf版本运行生成的胖子!
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")
这是我将配置加载到src文件夹中的一个文件中的方式:
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"
我可以看到环境变量已设置,并且环境已通过它.但是稍后我按如下方式加载application.test.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()
但是,它仅加载edfault application.conf,而不加载我指定的文件!
It however loads just the edfault application.conf and not the one that I specify!
我的情况有什么问题?我应该把conf文件夹放在哪里?我正在尝试针对测试文件夹中的单元测试运行它!
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!
推荐答案
好!这就是我要做的!更改配置文件所在的文件夹的名称.我最初将其作为conf,并且不得不将其重命名为资源,然后使其正常工作!
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!
这篇关于带有conf文件夹的Scala独立JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!