如何使用Maven组合罐子?

如何使用Maven组合罐子?,maven,maven-3,Maven,Maven 3,以下代码段创建了2个JAR: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <executions> <execution> &l

以下代码段创建了2个JAR:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>build-dependency</id>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>dependency</classifier>
                <classesDirectory>${project.build.directory}\dependency</classesDirectory>
                <includes>
                    <include>${dependancyInclude}</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>module</classifier>
                <classesDirectory>${project.build.directory}\classes</classesDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <!-- Combine all the JARs in the /target folder into one JAR -->
        <execution>
            <id>make-assembly</id>
            <phase>compile</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <attach>true</attach>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <appendAssemblyId>true</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>

org.apache.maven.plugins
maven jar插件
2.4
构建依赖项
编译
罐子
附属国
${project.build.directory}\dependency
${dependancyInclude}
编译
罐子
模块
${project.build.directory}\classes
我想使用汇编插件将这两个JAR组合成一个,目前我有以下内容:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>build-dependency</id>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>dependency</classifier>
                <classesDirectory>${project.build.directory}\dependency</classesDirectory>
                <includes>
                    <include>${dependancyInclude}</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>module</classifier>
                <classesDirectory>${project.build.directory}\classes</classesDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <!-- Combine all the JARs in the /target folder into one JAR -->
        <execution>
            <id>make-assembly</id>
            <phase>compile</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <attach>true</attach>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <appendAssemblyId>true</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>

maven汇编插件
2.2
组装
编译
单一的
真的
带有依赖项的jar
${project.artifactId}-${project.version}
真的

当前只有两个JAR中的一个包含在由汇编插件创建的最终JAR中。

如果我理解正确,您实际上希望将JAR文件合并到一个大JAR文件中。这可以使用maven shade插件(而不是maven assembly插件)实现

例如:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.0</version>
        <configuration>
           <!-- Put your configuration here, if you need any extra settings.
                (You should be okay with the defaults). -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

...
org.apache.maven.plugins
maven阴影插件
2
包裹
阴凉处
...

您想这样做的具体原因是什么?一般来说,规则是每个项目应该有一个工件。为什么要先创建两个工件,然后再将它们组合成一个?