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:
# Common options for all platforms
@bundle.jpackage.options.all=--name=MyApp --vendor="My Company" --description="My Application"
# Windows-specific options
@bundle.jpackage.options.windows=--icon=media/icon.ico --type=msi
# Linux-specific options
@bundle.jpackage.options.linux=--icon=media/icon.png --type=deb
# macOS-specific options
@bundle.jpackage.options.mac=--icon=media/icon.icns --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 use jdeps:compute to 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 --bind-services
# Platform-specific options
@bundle.jlink.options.windows=--launcher=myapp
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.
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¶
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.
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] | It true, the runtimes libs will be added in the packaged application, which may be not necessary whe using FAT jars. |
| jpackage.options.all.[key] [String] | |
| jpackage.options.windows.[key] [String] | |
| jpackage.options.linux.[key] [String] | |
| jpackage.options.mac.[key] [String] | |
| jlink.options.all.[key] [String] | |
| jlink.options.windows.[key] [String] | |
| jlink.options.linux.[key] [String] | |
| jlink.options.mac.[key] [String] |
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. |