Some brief examples on how to use this plugin. If you want to use advanced configurations you should have a look at the Example section. documentation for Maven Archiver.

To handle archiving this version of Maven JAR Plugin uses Maven Archiver 3.3.0.

Note: If you need to sign your JAR files you should use the Maven Jarsigner Plugin instead.

How to build a JAR file

When you want to create a JAR-file with Maven, you first have to create a pom.xml-file with at least the following content:

  <!-- <packaging>jar</packaging>  -->

Since 'jar' is the default packaging type it is not required to set it in this case. Apart from the above you will normally want some real java source files which should be located within src/main/java. If you need extra resources on your classpath (for example property files) they should be located in src/main/resources. Now we can create a JAR-file by using the command below:

mvn package

The 'package' phase is always responsible for bundling all the files in the artifact, in this case a JAR-file.

In your project's target directory you'll see the generated jar file which is named like: 'core-1.0-SNAPSHOT.jar'. The resulting 'jar' file contains the compiled java class files as well as the files from src/main/resources.

Usually there is no need to mentioned the 'maven-jar-plugin' explicit cause it's bound to the Maven Build Life Cycle.

For full documentation, click here.