Reputation: 4082
Can anyone explain the difference between building a jar for a maven project with and without maven plugins in pom.xml
I know that these plugins are useful in creating jar files in maven.
maven-jar-plugin builds jar
maven-assembly-plugin - builds jar with dependencies,
maven-shade-plugin - creates a standalone jar with resolved dependencies and resolves the conflicts between resource files that have the same name across the jars.
However i'm able to create a jar by running 'mvn package'command without using any plugin in my pom.xml. What's difference between this jar and the one generated using maven-jar-plugin.
Here's my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Demo</groupId>
<artifactId>Demo</artifactId>
<name>test</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
Upvotes: 1
Views: 854
Reputation: 11202
A maven project when using 'packaging=jar' uses the 'maven-jar-plugin' under to the hood. This creates a jar assuming you're following the maven standards. Hence your jar with no customisation.
You can further customise the generated jar using the 'maven-jar-plugin', where you might include extra files etc in the jar.
The 'maven-assembly-plugin' allows you to generate tar, zip and other compressed artifacts, with custom files and folder.
The 'maven-shade-plugin' allows you to creates a fat jar, which contains all the required 3rd party jars and main class. This makes your artifact easily deployable and executable.
Upvotes: 1