如何使用Maven在新jar中打包jar和所有依赖项 [英] How to package a jar and all dependencies within a new jar with maven

查看:769
本文介绍了如何使用Maven在新jar中打包jar和所有依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven项目,其中有十个依赖项.以前,由于maven-assembly-plugin:

I have a maven project with like ten dependencies. Before, I used to pack all of that in a single jar thanks to maven-assembly-plugin:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>create-executable-jar</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
                <archive>
                    <manifest>
                        <mainClass>myApp.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

但是现在,我之前添加了一个步骤.我有一个插件,它将生成我的应用程序的jar.因此,我只希望程序集插件将依赖项添加到此jar中.不幸的是,该插件未使用此jar,而是使用了编译器的结果.

But now, I added a step before. I have a plugin that will generate the jar of my application. So I just want the assembly plugin to add the dependencies to this jar. Unfortunately, the plugin doesn't use this jar, but instead, seems tu be using the result from the compiler.

是否可以指定我希望插件使用以前生成的jar而不是编译器的结果?

is there a way to specify that I want the plugin to use the previously generated jar instead of the result from the compiler ?

推荐答案

尝试使用maven-shade-plugin.您需要类似的东西:

Try using the maven-shade-plugin. You need something like:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这篇关于如何使用Maven在新jar中打包jar和所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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