Usage

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

How to build a jar file

If the packaging of your project is set to 'jar', this plugin is executed whenever it passes the "package" phase. You can execute it using the command below:

mvn package

In your project's target directory you'll able to see the generated jar file.

How to sign a jar file

If you need to sign your jar, you just need to configure the sign goal appropriately in your pom.xml, for the signing to occur automatically during the package phase.

Note that you can automatically verify a jar after signing it.

<project>
  ...
  <packaging>jar</packaging>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>sign</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <alias>youralias</alias>
          <storepass>yourstorepassword</storepass>
          <signedjar>${project.build.directory}/signed/${project.build.finalName}.jar</signedjar>
          <verify>true</verify>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

If you do not specify the <signedjar> file, your jar will be signed in-place. If you do specify it, the plugin will attempt to create the resulting containing directory.

How to sign a jar file specifying parameters on the command line

mvn jar:sign -Dkeystore=/path/to/your/keystore -Dstorepass=yourstorepassword -Dalias=youralias

How to verify a signed jar file specifying parameters on the command line

mvn jar:sign-verify [-Djarpath=/path/to/your/signedjar] [-Dverbose=true [-Dcheckcerts=true] ]

How to disable jar signing

mvn ... -Dmaven.jar.skip.sign=true

How to include/exclude content from jar artifact

Specify a list of fileset patterns to be included or excluded by adding <includes>/<include> or <excludes>/<exclude> in your pom.xml.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <includes>
            <include>**/service/*</include>
          </includes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Note that the patterns need to be relative to the path specified for the plugin's classesDirectory parameter.

How to create an additional attached jar artifact from the project

Specify a list of fileset patterns to be included or excluded by adding <includes>/<include> or <excludes>/<exclude> and add a classifier in your pom.xml.

Note: the jar-plugin must be defined in a new execution, otherwise it will replace the default use of the jar-plugin instead of adding a second artifact. The classifier is also required to create more than one artifact.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <classifier>client</classifier>
              <includes>
                <include>**/service/*</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

For full documentation, click here.