简体   繁体   中英

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

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 ?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM