5 Image and Runtime Modifications
The application image and Java runtime generated by the packaging tool work well for most applications. However, you can make changes to the image and runtime for any custom requirements that you might have, and then use the modified version when packaging your application.
Application Image Modifications
If needed, you can modify the application image that the packaging tool creates and then package the modified image for distribution.
Possible reasons for modifying the image include: adding removing files, adding resources, or changing the runtime. If you need to modify the image, run the packaging tool twice as follows:
-
Create only the application image with the
--type app-image
option. For example:jpackage --type app-image --name HelloWorld --module-path myModApps \ --module modhw/modhw.HelloWorldMod
In this example, a directory named
HelloWorld
is created in the current directory. TheHelloWorld
directory contains the application image, which contains the modular application in themyModApps
directory whose main class is in themodhw/modhw.HelloWorldMod
module. An installable bundle is not created. -
After you make the necessary changes to the application image, run the packaging tool again to create an installable bundle with the modified image. For example:
jpackage --type msi --app-image HelloWorld --name HelloWorld
Note:
-
The
--name
option is required when packaging an application image. -
The
--runtime-image
option is not allowed with--app-image
. You will get the following error:Error: Mutually exclusive options [--runtime-image] and [--app-image]
If you want to use a different runtime, then specify it when you first run
jpackage
to create the application image. For example:jpackage --type app-image --name HelloWorld \ --runtime-image myCustomJRE --module-path myModApps \ --module modhw/modhw.HelloWorldMod
Java Runtime Modifications
When you want more control over the Java runtime that is packaged with your application, you can create a custom runtime.
To create a custom Java runtime image for your application, run jlink
before you package your application. Then pass the image produced to the packaging tool using the --runtime-image
option. Reasons you might want to use a custom runtime image:
- Have more control over the options that are used to create the runtime
- Package your application with a different version of Java than the version used to run
jpackage
- Use the same runtime for more than one application.
For example, the following commands create a JDK 14 runtime that includes JavaFX 13 modules, and then package that runtime with an application:
jlink --output jdk-14+fx --module path javafx-jmods-13 \
--add modules javafx.web,javafx.media,javafx.fxml,java.logging
jpackage --name myapp --input lib --main-jar myApp.jar \
--runtime-image jdk-14+fx
If you are packaging an application that requires an earlier version of the Java
runtime, use the --runtime-image
option The following command packages the
JDK 11 runtime with your application:
jpackage --name myapp --input lib --main-jar myApp.jar \
--runtime-image jdk-11.0.5
If your application requires a custom runtime based on an earlier version of the JDK, use the earlier version to run jlink
and create the runtime image. Then use current JDK to run jpackage
and pass it the custom runtime. The following commands create a custom runtime using JDK 11.0.5 and package it using JDK 14:
c:\Program Files\Java\jdk-11.0.5\bin\jlink output my-jdk11 \
--add-modules java.desktop,java.datatransfer
c:\Program Files\Java\jdk-14\bin\jpackage --name myapp --input lib \
--main-jar myApp.jar --runtime-image my-jdk11