JDK-8186661 : Javapackager throws NullPointerException creating native image for simple java 9 module
  • Type: Bug
  • Component: deploy
  • Sub-Component: packager
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: other
  • CPU: x86
  • Submitted: 2017-08-22
  • Updated: 2017-09-21
  • Resolved: 2017-08-31
Description
FULL PRODUCT VERSION :
java version "9"
Java(TM) SE Runtime Environment (build 9+180)
Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 (x64)
Linux Mint 18 "Sarah" - Cinnamon (64-bit)
MacOSX (Sierra)

A DESCRIPTION OF THE PROBLEM :
According to this page http://openjdk.java.net/jeps/275 the javapackager should now have the --module and --module-path switches. However, I get a nullpointer when trying to build a simple HelloWorld-module with the javapackager. The very same error occurs on MacOSX and Linux as well as Windows. A native runtime image can be produced with the jlink command but fails with the javapackager.

REGRESSION.  Last worked in version 9

ADDITIONAL REGRESSION INFORMATION: 
java version "9"
Java(TM) SE Runtime Environment (build 9+180)
Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a simple com.example.Main-class. Create a module-info.java with the content i.e.

module helloworld.module {
    exports com.example;
}

2. Create a jar with the compiled class and a META-INF/MANIFEST.MF folder/file with the following:
Manifest-Version: 1.0
Main-Class: com.example.Main

3. Run the javapackager with the jar-file in module-path:
>javapackager -deploy -v -outdir release -name HelloWorldJava9 -native image --module-path "HelloWorldJava9.jar;C:\Program Files\Java\jdk-9\jmods" --module helloworld.module/com.example.Main


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expected result is that a native runtime image is created from the module.
ACTUAL -
C:\HelloWorldJava9\target>javapackager -deploy -v -outdir release -name HelloWorldJava9 -native image --module-path "HelloWorldJava9.jar;C:\Program Files\Java\jdk-9\jmods" --module helloworld.module/com.example.Main
Running [C:\Program Files\Java\jdk-9\bin\java.exe, -version]
Creating app bundle: HelloWorldJava9 in C:\HelloWorldJava9\target\release
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)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
same with the --add-modules switch:

C:\HelloWorldJava9\target>javapackager -deploy -v -outdir release -name HelloWorldJava9 -native image --module-path "HelloWorldJava9.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules helloworld.module --module helloworld.module/com.example.Main
Running [C:\Program Files\Java\jdk-9\bin\java.exe, -version]
Creating app bundle: HelloWorldJava9 in C:\HelloWorldJava9\target\release
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)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Main.java:

package com.example;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

module-info.java:

module helloworld.module {
    exports com.example;
}

META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: com.example.Main
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I can use jlink for now but later on I would like to package the app in exe/dmg/deb/rpm using the javapackager.

This works:

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


Comments
The problem is the module path. Try running the same CLI using java and it will not work. The error may be better or different but it still fails. The module path must contain only directory names, not file names. Attached is a project that works, and here is how you'd call it with java: $JAVA_HOME/bin/java --module-path `pwd`/modules --module hello.world/com.example.Main Also note that if you are packaging the jmods that came with the JDK you don't need to put that on the module path because it is picked up automatically.
31-08-2017

run: >bash compile.sh >bash package.sh
31-08-2017

Checked this on Windwows 10 (64-bit) with JDK 9 ea b181 and could confirm the output as reported. >javapackager -deploy -v -outdir release -name HelloWorldJava9 -native image --module-path "HelloWorldJava9.jar;C:\Program Files\Java\jdk-9\jmods" --module helloworld.module/com.example.Main Running [C:\Program Files\Java\jdk-9\bin\java.exe, -version] Creating app bundle: HelloWorldJava9 in D:\opt\ora\Deploy\9050574\release 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) To verify, run the attached test case provided in subsequent comment. This issue is also being discussed at stackoverflow: https://stackoverflow.com/questions/45446827/error-when-trying-to-package-native-image-with-javapackager-in-java-9-ea
23-08-2017