2014-09-04 73 views
1

我正在使用一个库(RootBeer),它需要额外的构建步骤:在创建我的JAR之后,我必须运行带有JAR作为其参数的RootBeer JAR以创建最终的启用RootBeer的JAR。Maven自定义包装

例如,如果我的罐子是myjar.jar,这是我必须用RootBeer创建最终的假象myjar-final.jar

java -jar rootbeer.jar myjar.jar myjar-final.jar 

我想知道是否有在Maven的一种机制,使我能够以这种方式建立一个神器。

现在我使用的gmaven-plugin用Groovy脚本,但这只是感觉太哈克,我敢肯定,我不能使用所产生的人工制品在其他项目的Maven依赖性:

<plugin> 
    <groupId>org.codehaus.groovy.maven</groupId> 
    <artifactId>gmaven-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>groovy-magic</id> 
     <phase>package</phase> 
     <goals> 
      <goal>execute</goal> 
     </goals> 
     <configuration> 
      <source> 
       println """java -jar target/rootbeer-1.2.0.jar target/myjar.jar target/myjar-final.jar""" 
        .execute().in.eachLine { 
         line -> println line 
       } 
      </source> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

有什么建议吗?

回答

3

您可以使用exec-maven-plugin执行您在Groovy中实施的最后一步,此外您还需要添加build-helper-maven-plugin以将补充工件添加到Maven中,以便将其与其余工件一起部署。

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.3.2</version> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>java</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <!-- The main class of rootbeer.jar --> 
       <mainClass>org.trifort.rootbeer.entry.Main</mainClass> 
       <!-- by setting equal source and target jar names, the main artefact is 
       replaced with the one built in the final step, which is exactly what I need. --> 
       <arguments> 
        <argument>${project.build.directory}/${project.artifactId}.jar</argument> 
        <argument>${project.build.directory}/${project.artifactId}.jar</argument> 
        <argument>-nodoubles</argument> 
       </arguments> 
      </configuration> 
     </plugin> 
+0

感谢您的回答。我不需要使用'build-helper-plugin',因为我可以设置可执行文件来替换主要的文件。 – 2014-09-04 15:50:47