Skip to main content

Maven

JavaPackager needs Maven 3.6 or newer and runs on Java 8 or newer. To bundle a customized JRE, build with a JDK 9 or newer.

Add the plugin​

Add the plugin to the build/plugins section of your pom.xml, with an execution of the package goal:

<plugin>
<groupId>io.github.javapackager</groupId>
<artifactId>javapackager</artifactId>
<version>2.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<mainClass>com.example.Main</mainClass>
<bundleJre>true</bundleJre>
</configuration>
</execution>
</executions>
</plugin>

Check the latest version on Maven Central or in the releases.

mainClass is the only mandatory property, and it can be omitted if the exec.mainClass property is set in your pom.xml:

<properties>
<exec.mainClass>com.example.Main</exec.mainClass>
</properties>

Package your app​

mvn package

The app and its installers are generated in target/. See generated artifacts for what you get, and which tools each installer needs.

By default the app doesn't bundle a JRE (bundleJre is false), so users need Java installed. With bundleJre set to true, as above, a customized JRE with only the modules your app needs is bundled with it.

A fuller example​

<configuration>
<!-- mandatory -->
<mainClass>com.example.Main</mainClass>
<!-- optional -->
<name>MyApp</name>
<displayName>My App</displayName>
<bundleJre>true</bundleJre>
<generateInstaller>true</generateInstaller>
<administratorRequired>false</administratorRequired>
<platform>auto</platform>
<vmArgs>
<vmArg>-Xmx512m</vmArg>
</vmArgs>
<additionalResources>
<additionalResource>README.md</additionalResource>
<additionalResource>config</additionalResource>
</additionalResources>
<linuxConfig>...</linuxConfig>
<macConfig>...</macConfig>
<winConfig>...</winConfig>
</configuration>

Every property is described in the configuration reference, and the platform-specific ones in GNU/Linux, macOS and Windows.

Properties taken from your project​

JavaPackager takes some values from the pom.xml, so you don't need to repeat them:

PropertyTaken from
namename, or artifactId if it has none
displayNamename (the project's, even if the plugin's name is set)
versionversion
descriptiondescription
urlurl
organizationName, organizationUrlorganization
licenseFilethe first license's url (downloaded), or a LICENSE file in the project folder
mainClassthe exec.mainClass property

More examples​

See the Maven samples: bundling a full or an existing JRE, your own fat JAR, several executions and several platforms.