我正在尝试使用 java 9-ea (jdk-9+180) 和新的 javapackager 从一个简单的模块创建本机映像,但出现空指针异常。有人知道我是不是太早了,还是我没有使用正确的命令开关来让它工作?jlink 命令可以正常工作,但 javapackager 不能。在撰写本文时,我使用的是最新的 jdk-9+180。我已尝试使用-native exe
和-native image
开关,但会出现相同类型的错误。我也在我的 Mac 上尝试了这个,用-native dmg
开关创建了一个本机 dmg,但是在那个平台上发生了同样的错误。我真的很喜欢在这里使用 javapackager 来捆绑构建exe/dmg
。
编辑 1: 我已提交有关此问题的错误报告,现在可以在以下 url 中看到它:http ://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8186661
我的模块信息.java:
module my.module {
requires javafx.graphics;
requires javafx.fxml;
exports sample;
}
首先,我使用 javapackager 创建一个 jar,它可以正常工作:
C:\Java9Test\target>javapackager -createjar -appclass sample.Main -srcdir classes -outdir . -outfile myjar -v
我已经验证了生成的 jar 结构对于正确编译module-info.class
的和其中的其他两个类看起来没问题。
以下 jlink 命令起作用并生成可运行的缩减运行时映像:
C:\Java9Test\target>jlink --output release\MyTestApp --compress=2 --module-path "myjar.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules my.module
但是,当尝试以下命令以使用 javapackager 创建本机映像时失败:
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
输出:
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)
编辑2:
-native exe
标志的输出(在 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)
编辑3:
-native dmg
标志的输出(在 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)
-native deb
标志的输出(在 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)
-native rpm
标志的输出(在 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)