2011-06-10 81 views
3

我想在做maven构建时替换现有jar/zip文件中的项目。什么是最简单的方法来实现这一点?谢谢。Maven - 用jar替换文件

+0

也许你应该提供更多的细节,例如解释你的问题是什么。谁知道,可能有一个解决方案,而不需要诉诸这个! – Raghuram 2011-06-12 02:20:31

回答

7

我最喜欢这类任务是maven-antrun-plugin,它为您带来完整的ant功能。

您可以使用它像这样:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.6</version> 
    <executions> 
     <execution> 
     <id>repack</id> 
     <phase>compile</phase> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     <configuration> 
      <target> 
      <!-- note that here we reference previously declared dependency --> 
      <unzip src="${org.apache:common-util:jar}" dest="${project.build.directory}/tmp"/> 
      <!-- now do what you need to any of unpacked files under target/tmp/ --> 
      <zip basedir="${project.build.directory}/tmp" destfile="${project.build.directory}/common-util-modified.jar"/> 
      <!-- now the modified jar is available --> 
      </target> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

但是请记住 - 从未修改你的本地库任何文件 - 在这个例子中通过${org.apache:common-util:jar}指向。这样做会影响您在同一台计算机上进一步构建所有项目(=针对同一本地回购)。

这样的构建在其他机器上也是不可重现的(或难以重现)。

+1

我更喜欢使用'antrun'插件,命令为'jar uf jar-file input-file(s)',如http://docs.oracle.com/javase/tutorial/deployment/jar/update.html – Vince 2012-12-06 15:18:04