This post covers a new tool, jpackage introduced in Java 14.
What is the Jpackage tool?
JPackage is a Java package tool to create installable packages for different environments.
It is an incubator feature, not stable with the java14 version in
jdk.incubator.jpackage. It provides a java application as a collection of JAR files and runs on platforms.
It allows users to distribute, install, and uninstall packages similar to native OS apps.
Why Jpackage tool required?
java applications run on end-user platform-specific environments. It is very difficult to ship, and install applications on the user machine, As it has a lot of dependencies in installing, setting classpaths, and configurations.
To resolve it, Jpackage provides an application to ship to the end user and runs on a platform-independent machine without worrying about dependencies and configurations.
Supports for following platform-specific packages. To generate packages for platforms, requires following tools required
- Windows: exe and msi, It requires WiX 3.0 or later
- MacOS: pkg and dmg, XCode command line tools
- Linux and Unix:
- deb and rpm.
- rpm-build is required for Red Hat Linux, fakeroot package is required for Ubuntu Linux
Jpackage Command line
Jpackage takes the java application, runtime image and output java application image with all dependencies.
--type or -t : package type, values are app-image,exe, msi, rpm, deb, pkg, dmg.
--app-version : package version
You can check more options
Here is an example
jpackage --name employeeapp --input lib --main-jar employee.jar
lib folder contains all lib dependencies
--main-jar contains main-class located in
employee.jar. if main-class not found, input main-class option
jpackage --name employeeapp --input lib --main-jar employee.jar --main-class com.organization.Main
It generates an application package in local native default format.