在一个jar中合并两个maven模块,并在指定位置生成第三个模块jar

时间:2017-03-07 00:33:49

标签: maven maven-plugin maven-assembly-plugin

我现在已经尝试了5个小时而且不确定我错过了什么。 我有以下

+- parent
   pom.xml
   +- core-module
      pom.xml
   +- excel-module
      pom.xml
   +- client-module
      pom.xml
   +- assembly-module
      pom.xml
  1. 我想为core.jar创建一个core-module and excel-module文件(我已经实现了)assembly-module/target/dist/server/core.jar
  2. 我想在client.jar
  3. 创建单独的assembly-module/target/dist/client/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>
    

    练成/ 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>
    

1 个答案:

答案 0 :(得分:0)

我实际上会尝试在assembly / pom.xml中添加另一个执行标记,如下所示:

 $(function () {
      $('#direct_upload input[type="file"]').cloudinary_fileupload(
        { dropZone: '#direct_upload',
         "transformation": "c_limit,h_400,w_400",
         "tags":"123"},

并添加一个新的程序集描述符文件(client-assembly-descriptor.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> 

您还需要在程序集项目中将客户端jar添加为依赖项。