如何使用Maven组合罐子? [英] How can I combine jars using Maven?

查看:65
本文介绍了如何使用Maven组合罐子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<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>

我想使用Assembly插件将这两个JAR合并为一个,目前我有以下内容:

<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>

当前,由程序集插件创建的最终JAR中仅包含两个JARS中的一个.

推荐答案

如果我对您的理解正确,那么您实际上想将jar文件合并为一个大的jar文件.可以使用maven-shade-plugin(而不是maven-assembly-plugin)来实现.

If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).

例如:

<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>

这篇关于如何使用Maven组合罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆