大家好!!
抱歉,如果这是一个愚蠢的问题,但我是 Maven 新手,已经陷入僵局!
- 我有一个使用 MyTest.properties、MoreMyTest.properties 的项目。
- 我使用 Maven Shade 插件将此项目构建为 .jar 文件,运行良好!不幸的是,shade 插件正在将 MyTest.properties 打包到我的 jar 文件中。
然后,当我尝试执行该 jar 时,出现此错误。
java.io.FileNotFoundException: Unable to locate: properties/MyTest.properties at file:\C:\Dev\test.jar!\properties\MyTest.properties at ...
我想在 IDE 中访问我的属性,并在部署时通过命令行运行 jar。我正在考虑将属性文件放在 jar 文件位置上方的相对文件夹 ../lib/中。
在我的程序中,我想访问如下属性:
File testProperties = new File(
ClassLoader.getSystemResource("properties/MyTest.properties").getFile()
);
我尝试将其添加到我的 POM.xml
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>*.properties</resource>
<file>../*properties</file>
</transformer>
(抱歉,上面的代码片段格式困惑!)
但是,它不起作用。我真的很感激任何帮助。我没有发布所有代码,因为代码确实很大,但我希望您能了解我想要实现的目标。
非常感谢, 保罗
最佳答案
好的,我有一个解决方案。总是这样,就在发布后!但谢谢你的回复。
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../lib</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
关于java - 相对于最终 Jar 的 Maven Shade 外部属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25552960/