

Use jpackage to Create Native Java App Installers
source link: https://www.devdungeon.com/content/use-jpackage-create-native-java-app-installers
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction
jpackage
is a new tool with JDK 14 that generates native system installers for distributing your appliction.
It will create .msi
for Windows, .dmg
for Mac, and .deb
or .rpm
for Linux distrubtions. This is ideal for GUI applications.
This guide will demonstrate how to use this tool to create system native installers for your applications.
jlink vs jpackage
jlink
was introduced in Java 9 and jpackage
builds on top of jlink
and came with Java 14.
jpackage
uses jlink
under the hood.
To understand jlink
better, check out my tutorial How to Create Java Runtime Images with jlink.
You can manually perform the jlink step before running jpackage, otherwise jpackage automatically invokes jlink during the process
jlink
generates the executable (e.g. .exe
, .app
), but jpackage
creates the installer for the executable (e.g. .msi
, .dmg
, .deb
, .rpm
).
Packaging non-modular apps
Though jpackage
only supports JDK11+, you can still build traditional non-modular apps.
This is the simplest example to demonstrate how jpackage
works.
You take an executable jar file, in this case myapp.jar
, and specify the class inside that you want to execute. The input directory tells jpackage
where to look for the JAR.
# input dir is where the main jar resides (`target/` typically with Maven projects)
# main jar path should be relative to the input dir
# main class is the executable class with a main() method
jpackage -i ./target/ --main-class com.devdungeon.Main --main-jar myapp.jar
This generates a single standalone .exe
file that will install your application.
Packaging modular apps
With a modular app, you have a couple options. You could use jlink
to build the runtime image first. You could include your application and dependencies in this runtime, or you can use jpackage
to
Automatically generate a runtime image
jpackage
will automatically run jlink
and generate a runtime with the modules needed. There is no need to run jlink
yourself unless you want something very custom. This example will generate the runtime and installer package with your module.
jpackage \
--module-path .;target/my.jar \
--module mymodule/com.devdungeon.Main \
--add-modules java.desktop,mymodule \
Use a custom runtime image
If you already have a runtime image with the modules in it, you can simply tell jpackage
to use the runtime image you want with the --runtime-image
option.
Specify the main class with the --module
option.
To learn how to create a custom runtime, check out my tutorial How to Create Java Runtime Images with jlink.
Here is an example of packaging an existing runtime to run a specific class.
jpackage \
--runtime-image my-custom-jre-with-app \
--module mymodule/com.devdungeon.Main
Add a startup splash screen
# APPDIR resolves to app final install dir
--java-options '-splash:$APPDIR/splash.png'
Associating file extensions with your app
--file-associations
For example, if I wanted to create a file extension .dano
for my application.
You can specify the following things for your custom file type:
- the file icon
- the mime-type you want to use
- the file extension
Common Windows options
Here are a few useful options when generating a Windows installer.
Let users choose the install directory
--win-dir-chooser
Creating a console launcher
# Create a console launcher for CLI applications
--win-console
Creating Start menu entry
# Add app to start menu
--win-menu
# defaults to "Unknown" folder without --win-menu-group
--win-menu-group <name>
# Create desktop shortcut
--win-shortcut
Install for user instead of system-wide
--win-per-user-install
Conclusion
After reading this guide, you should understand how to use jpackage
to generate a system-native installer for a Java application whether it is module or non-modular.
References
Recommend
-
48
In a Bugzilla report, Mozilla has revealed that they provide enterprise MSI installers starting with Firefox 65. By offering an MSI installer , system administrators can create their own transform files (MST) to easily customize the installation...
-
8
-
6
Flash Player Standalone Installers for Windows Tuesday, March 4, 2003 I have seen a lot of emails come in today asking how users can deploy the new Flash player on multiple machines. For these scenarios, we have a stand...
-
5
Transform 2021 Join us for the world’s leading event about accelerating enterprise transformation with AI and Data July 12-16, 2021
-
9
使用jlink +jpackage生成本地本机可执行Java程序或镜像将jlink和jpackage一起使用可以交付打包好的直接执行的Java应用程序,可以在不依赖最终用户安装特定 JDK 的情况下做到这一点,因为jlink在您的应用程序安装程序中为他们提供了他们需要的 JDK 子集。...
-
3
Open Source Installers Generators in JavaIzPackIzPack is an installers generator for the Java platform. It produces lightweight installers that c...
-
6
Pinned issues Clear current search que...
-
2
A Multi-Framework Composer Library Installer This is for PHP package authors to require in their composer.json. It will install their package to the correct location based on the spe...
-
9
Requirements Debian operating system. Windows operating system with Python 3, pip and inno setup installed. Creating inno setup installer (on windows) In order to create an insta...
-
7
US Department of Energy-funded solar marketplace EnergySage and nonprofit accreditation body The North American Board of Certified Energy Practitioners (
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK