I want to use maven-assembly-plugin to pack external dependencies into the application's jar file. When I call mvn install it creates two jar files, one with and one without the dependencies. (appname-version.jar and appname-version-jar-with-dependencies.jar)
My question is that why it creates two jar files?
Here is the plugin: (im not using any other plugin at the moment)
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.coolapp.mainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Thank you!
You need to define the maven-jar-plugin
to avoid creating the default jar. This is done by adding <phase>none</phase>
under execution
:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
All the resources/classes are still moved to the target folder, so maven-assembly
can still execute itself correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With