Filling the Packager gap

Sverre Moe sverre.moe at gmail.com
Thu Sep 27 08:42:36 UTC 2018


Den tor. 27. sep. 2018 kl. 00:49 skrev Kevin Rushforth <
kevin.rushforth at oracle.com>:

> No, jlink won't link in a non-modular application. So the steps are:
>
> 1) Run jlink to create a Java runtime image, possibly stripped down, and
> include the javafx.* modules you need
> 2) Run jpackager to package your non-modular application with the above
> Java runtime image.
>
> -- Kevin
>

So we have to create the image with the jlink first before we use
jpackager, and we have to link in with the javafx modules. We cannot use
the javafx dependencies in the project?

jlink --add-modules=ALL-SYSTEM --output image
Error: Module ALL-SYSTEM not found

The just to make sure we have everything we need I add the actual modules
jlink --add-modules=java.base --add-modules=java.desktop
--add-modules=java.net.http --add-modules=java.xml --add-modules=java.prefs
--add-modules=java.logging --output image

Linking in with the JavaFX jmods from Gluon:
jlink --add-modules=java.base --add-modules=java.desktop
--add-modules=java.net.http --add-modules=java.xml --add-modules=java.prefs
--add-modules=java.logging --module-path /usr/java/javafx-jmods-11/
--add-modules=javafx.base --add-modules=javafx.controls
--add-modules=javafx.fxml --add-modules=javafx.graphics
--add-modules=javafx.web --add-modules=javafx.media
--add-modules=javafx.swing --output image

I managed to build our Java 8 project with Java 11, using the JavaFX
dependencies.
Then using jpackager with the runtime image from jlink
/usr/java/jpackager/jpackager create-installer --input
build/distributions/application-1.0.0-SNAPSHOT/lib/ --output outputDir
--runtime-image image/ --verbose --echo-mode --main-jar
application-1.0.0-SNAPSHOT.jar

Running the application image from jpackager
First try:
I thought I had added all necessary modules to the runtime image, but I
needed one more, java.management.

Second try:
InteropFactory: cannot load
com.sun.javafx.embed.swing.newimpl.InteropFactoryN
Exception in thread "GUIBuilderWorker" java.lang.IllegalAccessError: class
com.sun.javafx.embed.swing.oldimpl.SwingNodeInteropO (in module
javafx.swing) cannot access class sun.swing.JLightweightFrame (in module
java.desktop) because module java.desktop does not export sun.swing to
module javafx.swing
       at
javafx.swing/com.sun.javafx.embed.swing.oldimpl.SwingNodeInteropO.<clinit>(SwingNodeInteropO.java:71)

       at
javafx.swing/com.sun.javafx.embed.swing.oldimpl.InteropFactoryO.createSwingNodeImpl(InteropFactoryO.java:42)

       at
javafx.swing/javafx.embed.swing.SwingNode.<init>(SwingNode.java:271)
       at no.company.application.fx.MySwingComponent.initNode(
MySwingComponent.java:155)

The module java.desktop should include the AWT/Swing.

At least I now have been able to create an native application using both
jlink and the new jpackager.

/Sverre


More information about the openjfx-dev mailing list