从 jar 生成的 exe 文件不在 Windows 中运行

问题描述

我在windows下用jpackager生成一个exe文件,当我安装并尝试运行时,产生了这个错误

Device initialization Failed for :  d3d,sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(UnkNown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(UnkNown Source)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(UnkNown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(UnkNown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(UnkNown Source)
        at java.base/java.lang.reflect.Method.invoke(UnkNown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(UnkNown Source)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(UnkNown Source)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(UnkNown Source)
        at java.base/java.lang.Thread.run(UnkNown Source)
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(UnkNown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(UnkNown Source)
        at java.base/java.lang.reflect.Method.invoke(UnkNown Source)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(UnkNown Source)
Caused by: java.lang.RuntimeException: No toolkit found
        at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(UnkNown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(UnkNown Source)
        ... 5 more

有关如何解决此问题的任何想法将不胜感激 这就是我生成exe文件的方式

jpackage -t exe --name "wetu" --app-version 1.0 --input "C:\Users\home\Documents\Andrew\Projects\Java\WetuLantern\dist" --dest "C:\Users\home\Documents\Andrew\wetu-exe" --main-jar "WetuLantern.jar" --icon "C:\Users\home\Documents\Andrew\icon.ico" --module-path "C:\Users\home\Downloads\Compressed\javafx-jmods-16" --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.base  --win-shortcut --win-menu --win-console

解决方法

使用 --win-console 激活 Windows 控制台,如本 answer 中所述。这允许您识别错误消息。

其次,安装程序不会在每次构建后升级 previous installation,除非您每次都增加 --app-version 或在安装新副本之前卸载之前的副本。