JavaPackager is a Maven plugin which provides an easy way to package Java applications in native Windows, Mac OS X, or GNU/Linux executables, and generates installers for them.
Add the following plugin
tag to your pom.xml
:
<plugin>
<groupId>io.github.fvarrui</groupId>
<artifactId>javapackager</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>package</goal>
</goals>
<configuration>
<mainClass>path.to.your.mainClass</mainClass>
<bundleJre>true|false</bundleJre>
<generateInstaller>true|false</generateInstaller>
<administratorRequired>true|false</administratorRequired>
<platform>auto|linux|mac|windows</platform>
<additionalResources>
<param>file path</param>
<param>folder path</param>
<param>...</param>
</additionalResources>
<additionalModules>
<param>module1</param>
<param>module2</param>
<param>...</param>
</additionalModules>
[...]
</configuration>
</execution>
</executions>
</plugin>
Some plugin configuration samples here.
Execute next command in project's root folder:
mvn package
And by default it will generate next artifacts in target
folder:
Artifact | Description |
---|---|
app |
Directory with the native application and other needed assets. |
projectname-projectversion-runnable.jar |
Runnable JAR file. |
projectname_projectversion.deb |
DEB package file if it's executed on GNU/Linux (requires dpkg-deb). |
projectname_projectversion.rpm |
RPM package file if it's executed on GNU/Linux (requires alien & rpmbuild). |
projectname_projectversion.exe |
Installer file if it's executed on Windows (requires Inno Setup). |
projectname_projectversion.dmg |
Disk image file if it's executed on Mac OS X (requires hdiutil). |
⚠️ DEB, RPM, EXE installer and DMG files will be ommited ifgenerateInstaller
plugin property isfalse
or if target platform is different from execution platform.
Property | Mandatory | Default value | Description |
---|---|---|---|
additionalModules |
❌ | [] | Additional modules to the ones identified by jdeps or the specified with modules property. |
additionalResources |
❌ | [] | Additional files and folders to include in the bundled app. |
administratorRequired |
❌ | false |
App will run as administrator (with elevated privileges). |
bundleJre |
❌ | false |
Embeds a customized JRE with the app. |
copyDependencies |
❌ | true |
Bundles all dependencies (JAR files) with the app. |
customizedJre |
❌ | true |
Generates a customized JRE, including only identified or specified modules. Otherwise, all modules will be included. |
description |
❌ | ${project.description} or ${displayName} |
Project description. |
displayName |
❌ | ${project.name} or ${name} |
App name to show. |
envPath |
❌ | null |
Defines PATH environment variable in GNU/Linux and Mac OS X startup scripts. |
generateInstaller |
❌ | true |
Generates an installer for the app. |
iconFile |
❌ | null |
Path to the app icon file (PNG, ICO or ICNS). |
jrePath |
❌ | "" |
Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
licenseFile |
❌ | ${project.licenses[0].url} or ${project.basedir}/LICENSE |
Path to project license file. |
mainClass |
✔️ | ${exec.mainClass} |
Full path to your app main class. |
modules |
❌ | [] | Defines modules to customize the bundled JRE. Don't use jdeps to get module dependencies. |
name |
❌ | ${project.name} or ${project.artifactId} |
App name. |
organizationName |
❌ | ${project.organization.name} or "ACME" |
Organization name. |
organizationUrl |
❌ | ${project.organization.url} |
Organization website URL. |
organizationEmail |
❌ | null |
Organization email. |
platform |
❌ | auto |
Defines the target platform, which could be different to the execution platform. Possible values: auto , mac , linux , windows . Use auto for using execution platform as target. |
runnableJar |
❌ | null |
Defines your own JAR file to be bundled. If it's ommited, the plugin packages your code in a runnable JAR and bundle it with the app. |
url |
❌ | null |
App website URL. |
version |
❌ | ${project.version} |
Project version in X.X.X format (e.g. 1.2.3), without letters. |
vmArgs |
❌ | [] | Adds VM arguments. |
See Older documentation for previous versions properties.
Some assets, such as application icons and Velocity templates, could be placed in assets
folder organized by platform.
<project>/
└── assets/
├── linux/
├── macosx/
└── windows/
If icons are located in assets
folders, it would not be necessary to specify the iconFile
property:
<project>/
└── assets/
├── linux/
│ └── projectname.png # on GNU/Linux it has to be a png image
├── macosx/
│ └── projectname.icns # on Mac OS X it has to be a icns file
└── windows/
└── projectname.ico # on Windows it has to be a ico file
projectname corresponds to
name
plugin property.
⚠️ IficonFile
plugin property is not specified and it can't find the correct icon inassets
folder, it will use an icon by default for all platforms.
Velocity templates (.vtl files) are used to generate some artifacts which have to be bundled with the app.
It is possible to use your own customized templates. You just have to put one of the following templates in the assets
folder organized by platform, and the plugin will use these templates instead of default ones:
<project>/
└── assets/
├── linux/
| ├── control.vtl # DEB control template
| ├── desktop.vtl # Desktop template
│ └── startup.sh.vtl # Startup script template
├── macosx/
| ├── Info.plist.vtl # Info.plist template
│ └── startup.vtl # Startup script template
└── windows/
├── exe.manifest.vtl # exe.manifest template
└── iss.vtl # Inno Setup Script template
Use default templates as examples.
A map called info
is passed to all templates when they are rendered with next properties:
Property | Type | Description |
---|---|---|
${info.name} |
String | Same as name plugin property. |
${info.displayName} |
String | Same as displayName plugin property. |
${info.version} |
String | Same as version plugin property. |
${info.description} |
String | Same as description plugin property. |
${info.url} |
String | Same as url plugin property. |
${info.organizationName} |
String | Same as organizationName plugin property. |
${info.organizationUrl} |
String | Same as organizationUrl plugin property. |
${info.organizationEmail} |
String | Same as organizationEmail plugin property. |
${info.administratorRequired} |
Boolean | Same as administratorRequired plugin property. |
${info.bundleJre} |
Boolean | Same as bundleJre plugin property. |
${info.jarFile} |
String | Full path to runnable JAR file. |
${info.license} |
String | Full path to license file. |
${info.envPath} |
String | Same as envPath plugin property. |
${info.vmArgs} |
String | Same as vmArgs plugin property. |
Execute next commands in BASH (GNU/Linux or macOS) or CMD (Windows):
- Download source code and change to the project directory:
git clone https://github.com/fvarrui/JavaPackager.git
cd JavaPackager
- Compile, package and install the plugin in your local repository and in the project's
releases
folder:
mvn install
mvn clean
mvn release:prepare
mvn release:perform
Related guide.
Check the TO-DO list to know the features we plan to add to JavaPackager.