2014-08-28 83 views
0

大家好!Maven Shade外部属性文件相对于最终Jar

对不起,如果这是一个愚蠢的问题,但我是新来的Maven,并已陷入僵局!

  1. 我有一个使用MyTest.properties,MoreMyTest.properties的项目。
  2. 我使用Maven Shade插件将此项目构建成.jar文件,该文件工作正常!不幸的是,阴影插件将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 (对不起格式上了上面的代码混乱snippet!)

但是,它不工作。我非常感谢这方面的帮助。我没有发布所有的代码,因为代码非常大,但是我希望你能了解我想要实现的目标。

非常感谢, 保罗

+0

我不确定你是否有maven阴影插件问题;我认为你有一个属性文件问题。考虑使用指向您的道具文件位置的系统属性。系统属性可以在运行时在命令行上和/或编程设置,因此它们最终对于这种事情来说非常灵活 – Gus 2014-08-28 16:07:35

+0

Hi @wax_lyrical我正面对着与apache maven shade插件完全相同的问题,你有没有解决方案这个?请发布 – prasshant 2016-07-19 17:10:44

回答

1

好吧,我有一个解决方案。始终如一,发布后!但是,谢谢你的回复。

<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>