[英]Executable Jar cannot find typesafe/config application.conf on classpath
我有一个命令行应用程序,可以下载一些报告,进行处理,然后将数据上传到Google云端硬盘。 我将Typesafe-Config用于所需的所有魔术字符串。 Typesafe-Config在我的application.conf文件的类路径上查找并使用HOCON将配置对象映射到我的类中的字段,如下所示:
从~/configs/application.conf
:
my.homePageUrl = "https://my.home.com"
从MyClass.java
:
private static Config config = ConfigFactory.load();
private static final String HOME_URL = config.getString("my.homePageUrl");
我正在使用maven-shade-plugin
构建可执行文件.jar,以便在远程服务器上轻松部署。 该插件如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.my.reports.ReportRunner</Main-Class>
<Class-Path>~/configs/application.conf</Class-Path>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
问题是,当我运行可执行文件.jar时,在我的类路径上找不到application.conf
(我猜这也可能是类型安全代码中的错误)。 所有这些在Intellij中都可以正常工作。
dustinevan@iMac:~/bin$ java -jar my-reports-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'my'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:147)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
at com.typesafe.config.impl.SimpleConfig.getList(SimpleConfig.java:212)
at com.typesafe.config.impl.SimpleConfig.getHomogeneousUnwrappedList(SimpleConfig.java:271)
at com.typesafe.config.impl.SimpleConfig.getStringList(SimpleConfig.java:329)
at com.stellarliving.reports.ecp.ReportRunner.<clinit>(ReportRunner.java:19)
dustinevan@iMac:~/configs$ ls
total 8
-rw-r--r--@ 1 dustinevan staff 1520 Jun 13 01:16 application.conf
我尝试了许多排列,并做了很多阅读来解决这个问题,我们将不胜感激。
因为我有同样的问题...
-jar
会覆盖所有类路径设置,因此只能看到jar。 -Dconfig.trace=loads
将显示Java看到的内容。
我们想要classpath和jar上的application.conf,所以: java -cp .:my-reports-1.0-SNAPSHOT.jar full.path.to.main.Main
为我完成了窍门。 找到了application.conf并覆盖了jar中的reference.conf。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.