2012-11-03 68 views
1

我正在使用Maven Assembly插件來打包一個可分配的ZIP壓縮文件。但是,我希望在最終歸檔中包含單獨的程序集結果,jar-with-dependencies。我怎樣才能做到這一點?我意識到我可能只是手動包含JAR,但是如何確保我的定製程序集在JAR程序集之後運行?在獨立程序集中包含jar -with-dependencies?

+0

可能的重複http://stackoverflow.com/questions/1522778/maven-assembly-plugin-how-to-create-nested-assemblies –

回答

2

您可以使用一個多模塊項目:

parent 
    |- ... 
    |- jar-with-dependencies-module 
    |- final-zip-module 

jar-with-dependencies模塊,你組裝「尤伯杯罐子」具有所有依賴性。在POM構建配置應該是這個樣子:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.3</version> 
     <configuration> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
     </configuration> 
     <executions> 
     <execution> 
      <phase>package</phase> 
      <goals> 
      <goal>single</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
</build> 

final-zip-module您可以添加jar-with-dependencies的依賴,並在裝配描述爲ZIP文件使用它。聚甲醛會是這個樣子:

<project> 
    ... 

    <dependencies> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>jar-with-dependencies-module</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
     <classifier>jar-with-dependencies</classifier> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.3</version> 
     <configuration> 
      <appendAssemblyId>false</appendAssemblyId> 
      <descriptors> 
      <descriptor>src/main/assembly/assembly.xml</descriptor> 
      </descriptors> 
     </configuration> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

而且裝配描述會是這個樣子:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 

    <id>final-assembly</id> 
    <formats> 
    <format>zip</format> 
    </formats> 

    <dependencySets> 
    <!-- Include the jar-with-dependencies --> 
    <dependencySet> 
     <includes> 
     <include>com.example:jar-with-dependencies-module:*:jar-with-dependencies</include> 
     </includes> 
     <useProjectArtifact>false</useProjectArtifact> 
     <!-- Don't use transitive dependencies since they are already included in the jar --> 
     <useTransitiveDependencies>false</useTransitiveDependencies> 
    </dependencySet>t> 
    </dependencySets> 
</assembly> 

由於依賴於jar-with-dependency-module的,Maven將您的尤伯杯後的jar總是建立final-zip-module被建。

+0

我不知道兩個項目是必要的 - 看到這篇文章:http: //download.csdn.net/questions/1522778/maven-assembly-plugin-how-to-create-nested-assemblies –

+0

@DuncanJones對,你也可以這樣做。而不是聲明'maven-assembly-plugin'兩次(正如http://stackoverflow.com/questions/1522778/maven-assembly-plugin-how-to-create-nested-assemblies中提出的),你也可以定義第二個在製作ZIP文件的第一個聲明中有''。這將節省幾行XML。 –

相關問題