How to package a jar and all dependencies within a new jar with maven

≯℡__Kan透↙ 提交于 2019-12-24 00:58:02

问题


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>

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.

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


回答1:


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>


来源:https://stackoverflow.com/questions/36158965/how-to-package-a-jar-and-all-dependencies-within-a-new-jar-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!