Bundle KBean¶
Bundle a self-contained Java app (containing JRE) using jpackage and jlink tools.
This plugin creates a self-contained app and allows configuring the jpackage and jlink tools.
This integrates with ProjectKBean for project-specific setups, handles file system operations to prepare input directories, and invokes jpackage and jlink tools.
Creates a customized self-contained app¶
Thanks to jpackage and jlink tools, this KBean creates self-contained Java applications or installers tailored for the host system.
To create such a bundle, execute: jeka bundle: pack.
The application or installer will be created in [project dir]/jeka-output dir.
If you want to create this bundle along other artifacts while executing jeka project: pack,
you need to specify the following property in jeka.properties:
@bundle.projectPack=true
Configuration Options¶
Properties¶
-
customJre- Iftrue, creates a custom JRE containing only the Java modules used by the application, using jlink. This reduces bundle size. -
projectPack- Iftrue, the bundled application is created automatically when executingjeka project: pack. -
includeRuntimeLibs- Iftrue(default), runtime dependencies are included in the packaged application. Set tofalsewhen using fat JARs.
JPackage Options¶
Configure jpackage using the @bundle.jpackage.options prefix in jeka.properties. Declare one property per option,
named after the platform (all, windows, linux or mac) and the option:
# Common options for all platforms
@bundle.jpackage.options.all.--name=MyApp
@bundle.jpackage.options.all.--vendor="My Company"
@bundle.jpackage.options.all.--description="My Application"
# Windows-specific options
@bundle.jpackage.options.windows.--icon=media/icon.ico
@bundle.jpackage.options.windows.--type=msi
# Linux-specific options
@bundle.jpackage.options.linux.--icon=media/icon.png
@bundle.jpackage.options.linux.--type=deb
# macOS-specific options
@bundle.jpackage.options.mac.--icon=media/icon.icns
@bundle.jpackage.options.mac.--type=dmg
Suggested options:
--name- Application name--vendor- Vendor name--description- Application description--icon- Application icon (platform-specific format)--type- Package type (app-image,exe,msi,deb,rpm,pkg,dmg)--add-modules- Additional JPMS modules to include (or useJDEPS-COMPUTEto auto-detect)--java-options- JVM options for the application--runtime-image- Path to custom JRE
JLink Options¶
When using customJre=true, configure jlink using the @bundle.jlink.options prefix:
# Common jlink options
@bundle.jlink.options.all.--compress=2
@bundle.jlink.options.all.--bind-services=
# Platform-specific options
@bundle.jlink.options.windows.--strip-debug=
Suggested options:
--add-modules- Modules to include in custom JRE--bind-services- Include service provider modules--compress- Compression level (0=none, 1=constant strings, 2=ZIP)--disable-plugin- Disable specific plugins--limit-module- Limit universe of observable modules
Advanced Usage¶
Automatic Module Detection¶
Use JDEPS-COMPUTE to automatically detect required JPMS modules:
@bundle.jpackage.options.all.--add-modules=JDEPS-COMPUTE
This analyzes the main JAR and its dependencies to determine which modules are needed. It has no effect when customJre=true.
Programmatic Configuration¶
In your KBean code, you can configure bundle options programmatically:
@JkInject
BundleKBean bundleKBean;
@Override
protected void init() {
bundleKBean.customJre = true;
bundleKBean.includeRuntimeLibs = false;
bundleKBean.addJpackageOptions("--vendor", "My Company");
bundleKBean.addJlinkOptions("--compress", "2");
}
Available Methods¶
bundle: pack- Creates the bundled application or installerbundle: computeModuleDeps- Prints JPMS module dependencies detected by jdepsbundle: jpackageHelp- Displays jpackage helpbundle: jlinkHelp- Displays jlink help
Summary¶
This KBean post-initializes the following KBeans:
| Post-initialised KBean | Description |
|---|---|
| ProjectKBean | Adds the bundled application to 'project: pack' actions, if 'projectPack=true'. |
This KBean exposes the following fields:
| Field | Description |
|---|---|
| customJre [boolean] | If true, a custom JRE is created including only Java modules used by the application. |
| projectPack [boolean] | If true, creates a bundled application along with the regular JAR when executing 'project: pack'. |
| includeRuntimeLibs [boolean] | If true, the runtime libs will be added in the packaged application, which may not be necessary when using FAT jars. |
| jpackage.options.all.[key] [String] | Extra options to pass to jpackage (e.g. 'jpackage.options.all.--name=myapp'). |
| jpackage.options.windows.[key] [String] | Extra options to pass to jpackage only when running on Windows. (e.g. 'jpackage.options.windows.--icon=media/icon.ico'). |
| jpackage.options.linux.[key] [String] | Extra options to pass to jpackage only when running on Linux. (e.g. 'jpackage.options.linux.--icon=media/icon.png'). |
| jpackage.options.mac.[key] [String] | Extra options to pass to jpackage only when running on MacOS. (e.g. 'jpackage.options.mac.--icon=media/icon.icns'). |
| jlink.options.all.[key] [String] | Extra options to pass to jlink (e.g. 'jlink.options.all.--compress=zip-6'). |
| jlink.options.windows.[key] [String] | Extra options to pass to jlink only when running on Windows. |
| jlink.options.linux.[key] [String] | Extra options to pass to jlink only when running on Linux. |
| jlink.options.mac.[key] [String] | Extra options to pass to jlink only when running on MacOS. |
This KBean exposes the following methods:
| Method | Description |
|---|---|
| computeModuleDeps | Prints JPMS module dependencies computed by jdeps. |
| jlinkHelp | Prints jlink help on the console. |
| jpackageHelp | Prints jpackage help on the console. |
| pack | Packages the application into a bundle. |