A Brief Example Using the Early Access jpackage Utility
by Jim Connors - 4 March 2019

JEP-343 (Java Enhancement Proposal 343) specifies the introduction and formal inclusion of an application packaging utility called jpackage into a future JDK.  Based on an earlier version of the JavaFX javapackager program, the goal of this tool is to provide native packaging options for Java applications on Windows, MacOS and Linux. From an end-user perspective, once Java applications have been packaged up with jpackage, installation experience should be no different than installing any other native app.  An early access, (and admittedly incomplete) build of OpenJDK 13 is now available for those who wish to experiment with this new feature.

As examples of this new utility are currently in scant supply, the video that follows walks through the process of taking a sample Java application and creating a native installer on MacOS for that program.

In a few short steps, the application source code is pulled from GitHub, built and packaged.  For those that wish to duplicate this demonstration, they can do so with the following prerequisites:

  1. Have a version of JDK 11 or later (either Oracle JDK or OpenJDK) installed and situated in your PATH such that it will be the first Java version found.
  2. If not already available, download and install Apache Maven and have it placed in your PATH also
  3. Likewise, if not already installed, download and install git and have it in your PATH too
  4. Download and install an early access version of OpenJDK that includes the jpackage utility.  You can find a version here.  Note, you currently must have both Java versions available.  You cannot attempt to take the jpacakage utility from the EA version of OpenJDK 13 and move it into JDK 11.  It won’t work.
Assuming your environment is set up correctly, there's only a few steps needed to get to the point of creating an application image, via jpackage, for our sample application: With this done you can run either version of the script below which invokes jpackage to create a native application installer: Here's what a sample jpackage incantation on MacOS looks like:

    /Users/jtconnor/Downloads/jdk-13.jdk/Contents/Home/bin/jpackage create-image --runtime-image image --input target --output appimage --name SocketClientFX --main-jar SocketClientFX-11.0.jar

Lets take a look at each individual component of the command: When complete, the single appimage/ directory contains the platform-specifc application directory.  In the video, the MacOS-genertated appimage/ directory has a SocketClientFX.app icon which is in reality a directory with multiple subdirectories.  To the MacOS finder application though, it looks like a properly formatted application and by simply dragging the SocketClientFX.app icon to the Applications folder, the SocketClientFX application is formally installed.

For the final step, you can convert the application image into a proper platform-specific installer using the jpackage create-installer directive.  The SocketClientFX project contains the following scripts which aid in the creation of installers:

As an example invocation on Windows, issuing

    powershell ps1\create-exe-installer.ps1 -e

would have a jpackage command-line which looks something like this:

    ~\Downloads\jdk-13\bin\jpackage.exe create-installer --installer-type exe --output "installer" --app-image "appimage/SocketClientFX" --name "SocketClientFX"

Please note, to create either an EXE or MSI installer on Windows does require third party applications (like, for example Inno or WiX toolkit respectively) to  be installed and available on your command-line PATH.

Conclusion
This article barely scratches the surface of the proposed jpackage tool.  For example, there are literally dozens of additional command options to provide image and installation customizations.  But it does at least provide one working example, which at this point is a bit of a rarity.  Expect more information to become available the this technology matures.