2011-06-10 83 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