2017-03-07 88 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

相关问题