javafxjava-9javapackager

Error when trying to package native image with javapackager in java 9-ea?


I'm trying out java 9-ea (jdk-9+180) and the new javapackager to create a native image from a simple module but I get a nullpointer exception. Anyone know if I'm just too early or if I'm not using the right command switches in order to get it to work? The jlink command works fine but the javapackager does not. I'm using the latest jdk-9+180 at the time of writing. I have tried both with the -native exe and -native image switches but the same type of error occurs. I have also tried this on my Mac creating a native dmg with the -native dmg switch, but the same error occurs on that platform. I'm really after using the javapackager here to be able to bundle the build in exe/dmg.

Edit 1: I have filed a bug report regarding this issue and it can now be visible at the following url: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8186661

My module-info.java:

module my.module {
    requires javafx.graphics;
    requires javafx.fxml;
    exports sample;
}

First I'm creating a jar with javapackager which works fine:

C:\Java9Test\target>javapackager -createjar -appclass sample.Main -srcdir classes -outdir . -outfile myjar -v

I have verified the resulting jar structure looks okay with the correct compiled module-info.class and the other two classes in it.

The following jlink command works and produces a runnable reduced runtime image:

C:\Java9Test\target>jlink --output release\MyTestApp --compress=2 --module-path "myjar.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules my.module

However, when trying the following command in order to create the native image using javapackager fails:

C:\Java9Test\target>javapackager -deploy -v -outdir packages -name MyTestApp -native image --module-path "myjar.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules my.module --module my.module/sample.Main

outputs:

Running [C:\Program Files\Java\jdk-9\bin\java.exe, -version] Creating app bundle: MyTestApp in C:\Java9Test\target\packages Exception: java.lang.NullPointerException Exception in thread "main" com.sun.javafx.tools.packager.PackagerException: Error: Bundler "Windows Application Image" (windows.app) failed to produce a bundle. at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:374) at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348) at jdk.packager/com.sun.javafx.tools.packager.Main.main(Main.java:496)

Edit 2:

Output from -native exe flag (on Windows)

Running [C:\Program Files\Java\jdk-9\bin\java.exe, -version] Running [C:\Program Files (x86)\Inno Setup 5\iscc.exe, /?] Detected [C:\Program Files (x86)\Inno Setup 5\iscc.exe] version [5] At least one type of shortcut is required. Enabling menu shortcut. Exception: java.lang.NullPointerException Config files are saved to C:\Users\Username\AppData\Local\Temp\fxbundler17330843784617821035\windows. Use them to customize package. Exception in thread "main" com.sun.javafx.tools.packager.PackagerException: Error: Bundler "EXE Installer" (exe) failed to produce a bundle. at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:374) at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348) at jdk.packager/com.sun.javafx.tools.packager.Main.main(Main.java:496)

Edit 3:

Output from -native dmg flag (on MacOSX)

Building DMG package for MyTestApp Exception: java.lang.NullPointerException Config files are saved to /var/folders/qs/nk3vxsx90q9_pbjs0ypg74r40000gn/T/fxbundler3765252041328710759/macosx. Use them to customize package. Exception in thread "main" com.sun.javafx.tools.packager.PackagerException: Error: Bundler "DMG Installer" (dmg) failed to produce a bundle. at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:374) at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348) at jdk.packager/com.sun.javafx.tools.packager.Main.main(Main.java:496)

Output from -native deb flag (on Linux Mint)

Running [dpkg-deb, --version] Debian packages should specify a license. The absence of a license will cause some linux distributions to complain about the quality of the application. Exception: java.lang.NullPointerException Config files are saved to /tmp/fxbundler2941553392593775128/linux. Use them to customize package. Exception in thread "main" com.sun.javafx.tools.packager.PackagerException: Error: Bundler "DEB Installer" (deb) failed to produce a bundle. at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:374) at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348) at jdk.packager/com.sun.javafx.tools.packager.Main.main(Main.java:496)

Output from -native rpm flag (on Linux Mint)

Running [rpmbuild, --version] At least one type of shortcut is required. Enabling menu shortcut. Exception: java.lang.NullPointerException Config files are saved to /tmp/fxbundler2278571164448075269/linux. Use them to customize package. Exception in thread "main" com.sun.javafx.tools.packager.PackagerException: Error: Bundler "RPM Bundle" (rpm) failed to produce a bundle. at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateNativeBundles(PackagerLib.java:374) at jdk.packager/com.sun.javafx.tools.packager.PackagerLib.generateDeploymentPackages(PackagerLib.java:348) at jdk.packager/com.sun.javafx.tools.packager.Main.main(Main.java:496)


Solution

  • Answering my own question here (after having received a reply on the bug-report):

    It turns out that the module-path must contain only directory names, not file names, hence you can not specify the jar in the path as you can with the jlink command. The javapackager works with the module-path if set to the compiled module-classes like below, also you don't need to put in the module-path to the jmods directory because it is picked up automatically.

    C:\Java9Test\target>javapackager -deploy -v -outdir packages -name MyTestApp -native image --module-path C:\Java9Test\target\classes --module my.module/sample.Main

    However, the resulting build's executable MyTestApp.exe did not work for me, nothing happened when invoked (double-clicked). Also the build is quite bulky and it seems you can not use the --compress=2 and --strip-debug flags yet as you can with jlink. However, I discovered that you can actually replace the content of the runtime folder produced with the javapackager with the output from the jlink command giving the build a much smaller footprint and the MyTestApp.exe works when invoked! I could also delete the java.exe and javaw.exe from the replaced runtime\bin folder as well as the msvcp120.dll and msvcr120.dll from the main MyTestApp-folder since those dll:s are already in the MyTestApp\runtime\bin folder.

    MyTestApp-folder structure:

    folder-structure.