2014-01-17 71 views
2

我有一個模塊,而建立這個模塊,我想包括一些外部jar的資源到我的模塊jar。如何將外部jar的資源添加到我的maven build jar中?

我試圖使用maven-shade-plugin,但我無法實現它。

任何幫助表示讚賞。

+0

什麼resurce?有點像'.properties'? – MariuszS

+0

是的和一些.xsb文件 – saurav

+2

是否有任何特定的原因,你想要做到這一點?你不想將外部jar建立到你的模塊中? – Sashi

回答

2

將此外部資源解壓縮到項目目標中,解壓後的資源將包含在生成的工件中。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>unpack</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>unpack</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
        <artifactItem> 
         <groupId>foo</groupId> 
         <artifactId>bar</artifactId> 
         <version>1.0</version> 
         <type>jar</type> 
         <includes>*.xsb, *.properties</includes> 
        </artifactItem> 
       </artifactItems> 
       <outputDirectory>${project.build.outputDirectory}</outputDirectory> 
       <overWriteReleases>true</overWriteReleases> 
       <overWriteSnapshots>true</overWriteSnapshots> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

對於非行家文件使用的方法從這個答案https://stackoverflow.com/a/3264160/516167

+0

感謝您的回答......但我有一個約束,這個外部罐子沒有安裝爲maven工件。有沒有可能給這個jar文件的(C:\ external.jar)絕對位置,而不是提到它的maven座標? – saurav

+1

是的,http://stackoverflow.com/a/3264160/516167 – MariuszS

+1

謝謝,它爲我工作:)。 – saurav