User Guide

These are quick instructions on how to use the Packager plugin.

For a complete list of the possible parameter to Packager see the Parameters section.

Simple usage to build source and runnable packages

Packager relies on convention for most tasks.

So the following simple example has more than meets the eye

 1    <plugin>
 2      <groupId>pt.digitalis</groupId>
 3      <artifactId>maven-packager-plugin</artifactId>
 4      <configuration>
 5        <sourcePackage>true</sourcePackage>
 6        <runnablePackage>true</runnablePackage>
 7        <distributionPackage>true</distributionPackage>
 8      </configuration>
 9      <executions>
10        <execution>
11          <phase>package</phase>
12          <goals>
13            <goal>package</goal>
14          </goals>
15        </execution>
16      </executions>
17    </plugin>

We can see here that we issue three configurations parameters:

  • sourcePackage: Instructs the plugin to generate a source code package. By convention the name will be "$artifactId-source.zip" and it will be saves in the target directory.
  • runnablePackage: Instructs the plugin to generate a runnable jar package. By convention the name will be "$artifactId-runnable.zip" and it will be saves in the target directory. This zip will contain the generated jar file and launcher files for windows and linux.
  • distributionPackage: Instructs the plugin to generate a distribution package. By convention the name will be "$artifactId.zip" and it will be saves in the target directory. This zip will contain the generated jar file.

We can also notice that this configuration links the package generation to the "package" phase of the POM build cycle. So whenever we issue a "mvn package" command our packages will be generated.

Usage that takes advantage of the OneJar Maven plugin

Packager is prepared to take advantage of a OneJar jar file when present.

To use such a configuration we'll need to configure our POM file as follows:

 1    <plugin>
 2      <groupId>org.dstovall</groupId>
 3      <artifactId>onejar-maven-plugin</artifactId>
 4      <executions>
 5        <execution>
 6          <goals>
 7            <goal>one-jar</goal>
 8          </goals>
 9        </execution>
10      </executions>
11    </plugin>
12
13    <plugin>
14      <groupId>pt.digitalis</groupId>
15      <artifactId>maven-packager-plugin</artifactId>
16      <configuration>
17        <sourcePackage>true</sourcePackage>
18        <runnablePackage>true</runnablePackage>
19        <outputDirectory>src/site/resources/files</outputDirectory>
20      </configuration>
21      <executions>
22        <execution>
23          <phase>package</phase>
24          <goals>
25            <goal>package</goal>
26          </goals>
27        </execution>
28      </executions>
29    </plugin>

Here we see the inclusion of the OneJar plugin and it's linkage to the package goal. More on this can be seen in the plugin's web site here.

By convention we won't need to do more than this for Packager to pick up the OneJar file instead of the normal one.

Here we can see yet another new addition to the previous example: The outputDirectoryPackage. This parameter tells Packager where to save the generated packages to.

Custom packages

The last example is the building of a custom package. Here we wish to build a zip file containing an arbitrary set of files. All this we have to supply since here convention cannot help us.

 1    <plugin>
 2      <groupId>pt.digitalis</groupId>
 3      <artifactId>maven-packager-plugin</artifactId>
 4      <configuration>
 5        <packageFileName>myPackage.zip</packageFileName>
 5        <files>
 6          <param>File1.txt</param>
 7          <param>SomeDirectory/subDirectory</param>
 8        </files>
 9        <outputDirectory>src/site/resources/files</outputDirectory>
10      </configuration>
11      <executions>
12        <execution>
13          <phase>package</phase>
14          <goals>
15            <goal>package</goal>
16          </goals>
17        </execution>
18      </executions>
19    </plugin>

You can notice here that a file set has been given. These are the files that will be added to the new zip package file. You can also notice that we can give files and directories. Directories will be added with all subcontents included, including subdirectories.