如何在Maven2中将模块jar合并到单个jar? [英] How to merge module jars to a single jar in Maven2?

查看:323
本文介绍了如何在Maven2中将模块jar合并到单个jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个jar模块的maven2项目,构建该项目将在目录modules/XYZ/target/XYZ-x.x.x.jar

I have a maven2 project with several jar modules, build the project will get .jar archives for each module in the directory modules/XYZ/target/XYZ-x.x.x.jar

现在,如果我的项目P是P-p.q.r版本,并且我想生成一个包含所有子模块的jar P-p.q.r-all.jar,我该怎么办?

Now, if my project P is of version P-p.q.r, and I want to generate a single jar P-p.q.r-all.jar with all sub-modules included in, how should I do?

推荐答案

您想要实现的目标称为超级罐子.该模块必须依赖于要打包到一个jar中的所有其他子模块.如果创建另一个将产生所需工件的子模块,则可以在反应堆中构建所有具有其依赖项的子模块,但是如果它将是一个单独的项目,则必须安装所有超级jar依赖项.

What you want to achive is called uber jar. This module has to have dependecies of all others submodules you want to package into one jar. If you create another submodule that will produce a desired artifact it can be built in reactor with all its dependencies but if it will be a separate project that you have to install all uber jar dependecies.

| parent
| -- submodule1
...
| -- submoduleN
| -- uberjarSubmodule

Uber jar可以通过以下方式完成:

Uber jar can be done by using:

  1. maven-shade-plugin -在您的情况下您必须记住从模块中排除传递依赖项

  1. maven-shade-plugin - in your case you have to remember to exclude transitive dependecies from your modules

<project>
...
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.2.2</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <artifactSet>
            <excludes>
              <exclude>classworlds:classworlds</exclude>
              <exclude>junit:junit</exclude>
              <exclude>jmock:jmock</exclude>
              <exclude>xml-apis:xml-apis</exclude>
            </excludes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
</build>
...
</project>

  • maven-assembly-plugin -在问题,您将找到详细的答案

  • maven-assembly-plugin - in this question you'll find a detailed answer

    这篇关于如何在Maven2中将模块jar合并到单个jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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