3

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)

jbilander
  • 611
  • 4
  • 15
  • do you have Inno Setup 5 installed and available via PATH? Check paragraph 7.4.1 here http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html – madduci Aug 29 '17 at 12:23
  • Yes I have and now also added "edit 2" where you can see the output from running with -native exe flag instead of -native image. The error does not seem to be related to InnoSetup. NullPointerException at the very same line regardless of which flag is used (image/exe/dmg/deb/rpm). I have bug-reported to Oracle... – jbilander Aug 29 '17 at 13:27
  • it looks like a bug on Windows. On linux, the same command can generate deb,rpm,images. BTW, you can build a package only on specific systems (e.g., DEB/RPM only on linux, EXE/MSI only on Windows, DMG only on Mac) – madduci Aug 30 '17 at 06:25
  • I'd say it looks like a bug regardless of platform, see "edit 3"... – jbilander Aug 30 '17 at 10:08
  • Rather sad that the bug was closed as "not an issue" with that confusing error message and with the additional need for shuffeling around files and direcvtories to get a clean module-path structure (instead of simply pinking the *.jar file like jlink can). Did you try to contact a openjdk mailing list? – eckes Mar 16 '18 at 02:50
  • no, I never tried to contact anyone at openjdk mailing list regarding this issue. I agree with you, it would be nice if the *.jar file could be specified in the module-path like you can do in jlink. – jbilander Mar 19 '18 at 09:56

1 Answers1

5

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.

jbilander
  • 611
  • 4
  • 15
  • together with the module-path to your Java files, you should chain also the path to Java jmods folder: --module-path C:\Java9Test\target\classes;C:\Program Files\Java\jdk-9\jmods – madduci Sep 06 '17 at 06:13
  • Actually, there is no need for doing that since the path to jmods is picked up automatically by the javapackager. However, when running the jlink-command it seems necessary to do so. – jbilander Sep 06 '17 at 06:51