2015-05-20 30 views
0

我想在使用遮罩插件的OSGi包之一中合并openwebbeans.properties文件,这些文件出现在2个依赖项(openwebbeans-impl,openejb-core)中。 我按照色调文档上 我的配置如下:https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer使用Apache遮罩插件合并.properties文件

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.3</version> 
     <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
        <configuration> 
         <transformers> 
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
            <resource>META-INF/openwebbeans/openwebbeans.properties</resource> 
          </transformer> 
         </transformers> 
        </configuration> 
       </execution> 
      </executions> 
    </plugin> 

但是当我尝试MVN干净安装失败,以下错误

[INFO] --- maven-shade-plugin:2.3:shade (default) @ tomee --- 
[ERROR] The project main artifact does not exist. This could have the following 
[ERROR] reasons: 
[ERROR] - You have invoked the goal directly from the command line. This is not 
[ERROR] supported. Please add the goal to the default lifecycle via an 
[ERROR] <execution> element in your POM and use "mvn package" to have it run. 
[ERROR] - You have bound the goal to a lifecycle phase before "package". Please 
[ERROR] remove this binding from your POM such that the goal will be run in 
[ERROR] the proper phase. 
[ERROR] - You removed the configuration of the maven-jar-plugin that produces the main artifact. 
[INFO] ------------------------------------------------------------------------ 

有人能告诉我有什么错误,在我组态? 这是做什么的正确方法?

编辑

据struberg它提供的答案似乎是我的尝试是不适用于openwebebans上下文。但是我仍然想知道合并属性文件的正确方式是什么。或者如何解决这个问题。

+0

我的猜测:阴影插件在打包插件之前调用。解决这个问题的最好方法是在''部分提及插件,在这里你首先提到包装插件,然后是阴影插件。当插件绑定到同一阶段时,Maven会自上而下评估它们。 –

+0

@RobertScholte它是pom中的最后一个插件。我甚至改变了顺序并把它放在第一位。但没有运气 –

回答

1

棘手的部分是我们在每个文件中都有一个'configuration.ordinal'属性。这定义了信息以何种顺序被“合并”。较高的序数值将稍后应用于较低的序号配置。因此,来自更高序号配置的配置设置将保持不变。

阅读更多在https://struberg.wordpress.com/2010/09/21/flexible-configuration-for-modular-systems/

+0

那篇文章解释它非常好。所以我认为虽然我的问题仍然有效,但它不适用于openwebbeans环境。非常感谢链接。我UPVOTED答案:)我也编辑了这个问题。 –

+1

也许可以创建一个自己的阴影转换器并使用PropertyLoader.getProperties(..)并将结果写入新文件? – struberg

+0

这是一个很好的建议。 –