2017-03-07 13 views
0

我一直在嘗試5個小時,不知道我錯過了什麼。 我有以下將兩個maven模塊合併到一個jar文件中,並在指定位置生成jar第三個模塊

+- parent 
    pom.xml 
    +- core-module 
     pom.xml 
    +- excel-module 
     pom.xml 
    +- client-module 
     pom.xml 
    +- assembly-module 
     pom.xml 
  1. 我想創建core-module and excel-module一個core.jar文件(我已經實現)assembly-module/target/dist/server/core.jar
  2. 我想在assembly-module/target/dist/client/client.jar

創建單獨client.jar文件以下是我的POM文件。

芯/ pom.xml的

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<parent> 
    <groupId>com.test.project</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0.0.0-SNAPSHOT</version> 
</parent> 
<artifactId>core</artifactId> 
<dependencies> 
    <dependency> 
     <groupId>com.test.project</groupId> 
     <artifactId>excel</artifactId> 
     <version>${project.version}</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 
</project> 

的excel/pom.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<parent> 
    <artifactId>parent</artifactId> 
    <groupId>com.test.project</groupId> 
    <version>1.0.0.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 
<artifactId>excel</artifactId> 
<dependencies> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
     <version>3.3.2</version> 
    </dependency> 
</dependencies> 
</project> 

客戶機/ pom.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://maven.apache.org/POM/4.0.0" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<parent> 
    <artifactId>parent</artifactId> 
    <groupId>com.test.project</groupId> 
    <version>1.0.0.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 
<artifactId>client</artifactId> 
<packaging>jar</packaging> 
<build> 
    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <configuration> 
       <archive> 
        <manifestEntries> 
         <Build-Version>${project.version}</Build-Version> 
        </manifestEntries> 
       </archive> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<dependencies> 
     <dependency> 
      <groupId>com.test.project</groupId> 
      <artifactId>core</artifactId> 
      <version>${project.version}</version>> 
     </dependency> 
</dependencies> 

組裝/ pom.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<parent> 
    <artifactId>parent</artifactId> 
    <groupId>com.test.project</groupId> 
    <version>1.0.0.0-SNAPSHOT</version> 
</parent> 
<modelVersion>4.0.0</modelVersion> 

<artifactId>assembly</artifactId> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>3.0.0</version> 
      <executions> 
       <execution> 
        <id>assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
        <configuration> 
         <descriptors> 
          <descriptor>src/main/assembly- descriptor.xml</descriptor> 
         </descriptors> 
         <appendAssemblyId>false</appendAssemblyId> 
         <outputDirectory>${project.basedir}/target/dist/server/</outputDirectory> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <finalName>core</finalName> 
</build> 
<dependencies> 
    <dependency> 
     <groupId>com.test.project</groupId> 
     <artifactId>excel</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.test.project</groupId> 
     <artifactId>core</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
</dependencies> 

裝配/ descriptor.xml

<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>all-jar</id> 
<formats> 
    <format>jar</format> 
</formats> 

<includeBaseDirectory>false</includeBaseDirectory> 

<dependencySets> 
    <dependencySet> 
     <unpack>true</unpack> 
     <useTransitiveDependencies>false</useTransitiveDependencies> 
    </dependencySet> 
</dependencySets> 
</assembly> 

在我需要更新assembly.xml和/或descriptor.xml達到第二點什麼樣的方式。我看幾乎所有相關的帖子在這裏SO

任何幫助,非常感謝。

編輯

<build> 
<plugins> 
    <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>3.0.0</version> 
     <executions> 
      <execution> 
       <id>core-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
       <configuration> 
        <descriptors> 
         <descriptor>src/main/core-assembly-descriptor.xml</descriptor> 
        </descriptors> 
        <appendAssemblyId>false</appendAssemblyId> 
        <outputDirectory>${project.basedir}/target/dist/framework/lib/server/</outputDirectory> 
        <finalName>core.jar</finalName> 
       </configuration> 
      </execution> 
      <execution> 
       <id>client-assembly</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
       <configuration> 
        <descriptors> 
         <descriptor>src/main/client-descriptor.xml</descriptor> 
        </descriptors> 
        <appendAssemblyId>false</appendAssemblyId> 
        <outputDirectory>${project.basedir}/target/dist/framework/runtime/</outputDirectory> 
        <finalName>client.jar</finalName> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 

回答

0

我真的嘗試添加另一個執行標籤在裝配/ pom.xml的,如下:

<execution> 
       <id>assembly-client</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
       <configuration> 
        <descriptors> 
         <descriptor>src/main/client-assembly-descriptor.xml</descriptor> 
        </descriptors> 
        <appendAssemblyId>false</appendAssemblyId> 
        <outputDirectory>${project.basedir}/target/dist/client/</outputDirectory> 
       </configuration> 
      </execution> 

,並添加一個新的裝配描述符文件( client-assembly-descriptor.xml)如下:

<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>all-jar</id> 
    <formats> 
<format>jar</format> 
    </formats> 
     <includeBaseDirectory>false</includeBaseDirectory> 
    <dependencySets> 
<dependencySet> 
    <unpack>true</unpack> 
    <useTransitiveDependencies>false</useTransitiveDependencies> 
    <includes> 
    <include>com.test.project:client</include> 
    </includes> 
</dependencySet> 

您還需要在組裝項目中添加客戶端jar作爲依賴項。

+0

感謝@htulsiani,我怎麼能到這兩個給出不同的名字'jars'由於行家更新不再支持''內'標籤<配置>'現在支持外''我與您的更改編輯 – vairowalia

+0

nvmd我明白了:) – vairowalia

相關問題