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. The first time you run it, use the --type app-image option to create only the application image:

jpackage --type app-image --name HelloWorld --input helloworld \
   --main-jar HelloWorld.jar

A directory named HelloWorld is created in the current directory and contains the application image. 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:

jpackage --type msi --app-image HelloWorld --name HelloWorld

Notes:

  • The --name option is required when packaging an application image.

  • The --runtime-image option is not allowed with --type app-image. If you want to use a different runtime, pass it in when you create the application image that you plan to modify.

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