使用JDK 11在Mac上打开.jar文件失败,并显示RuntimeException

时间:2018-11-16 23:04:25

标签: java macos jar java-11 javafx-11

我正在尝试在MAC Mojave 10.14上打开一个.jar文件(https://github.com/ptrckbnck/SQLChecker/releases),我的大学课程需要它。

我做了什么:

java -version

openjdk version "11.0.1" 2018-10-16  
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)  
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)  

但是当我运行java -jar SQLChecker-1.0.jar时,我继续遇到以下异常:

Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
at com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:222)
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:260)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
... 1 more
Exception in thread "main" java.lang.RuntimeException: No toolkit found
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)

我已经阅读了相关主题Migration to JDK 11 + JavaFX 11 giving RuntimeException,并从此处https://gluonhq.com/products/javafx/下载了JavaFX 11,即JavaFX Mac OS X SDK。我还运行以下代码:

export PATH_TO_FX=my/path/to/javafx-sdk-11/lib

并按照https://openjfx.io/openjfx-docs/所述使用JavaFX 11运行HelloWorld测试。一切正常,但不能解决我原来的问题。 正如@Drimux在相关线程中所建议的那样,OpenJDK发行版中缺少某些库。他感到遗憾的是,这些文件可能是libprism_es2.dylib,libprism_sw.dylib,libglass.dylib,libjavafx_font.dylib。因此,我将这些文件从javafx-sdk-11.0.1 / lib复制到/Library/Java/JavaVirtualMachine/jdk-11.0.1.jdk/Contents/Home/lib,然后尝试再次运行.jar文件。有新的例外:

GLFactory.static - Platform: Mac OS X - not available: com.sun.prism.es2.MacGLFactory
java.lang.ClassNotFoundException: com.sun.prism.es2.MacGLFactory
at   java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at com.sun.prism.es2.GLFactory$FactoryLoader.run(GLFactory.java:108)
at com.sun.prism.es2.GLFactory$FactoryLoader.run(GLFactory.java:100)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.prism.es2.GLFactory.<clinit>(GLFactory.java:97)
at com.sun.prism.es2.ES2Pipeline.<clinit>(ES2Pipeline.java:76)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at com.sun.prism.GraphicsPipeline.createPipeline(GraphicsPipeline.java:187)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:91)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
at java.base/java.lang.Thread.run(Thread.java:834)
java.lang.ClassNotFoundException: com.sun.glass.ui.mac.MacPlatformFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at com.sun.glass.ui.PlatformFactory.getPlatformFactory(PlatformFactory.java:42)
at com.sun.glass.ui.Application.run(Application.java:144)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:258)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Failed to load Glass factory class
Exception in thread "main" java.lang.NullPointerException
at com.sun.glass.ui.Application.run(Application.java:144)
at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:258)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:269)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)

这不能解决问题。如果您需要更多信息,请提出要求。 我还应该尝试什么?

1 个答案:

答案 0 :(得分:2)

如果您是从第一个测试release下载的jar,则运行时如下所示:

java -jar SQLChecker-1.0.jar

您将获得发布的异常。

作为第一个简单的解决方法,如果您已经下载了JavaFX 11 SDK,请运行以下命令:

java --module-path /path-to/javafx-sdk-11/lib --add-modules javafx.controls,javafx.fxml -jar SQLChecker-1.0.jar

您可以了解为什么需要这些VM参数here

无论如何,您都不应将本机文件从JavaFX SDK复制到JDK。

新版本

但是还有两个新版本的SQLChecker。

如果您尝试使用最后一个one

java -jar SQLChecker-1.0.3.jar

可以正常工作,而无需添加额外的参数。

那有什么改变?

他们正在分发带有Maven阴影插件的胖jar,并且为了在任何平台上使用JavaFX 11,您不仅需要包括jar,还必须包括本地库。

您可以看到,在此commit中,通过为classifier包含javafx.graphics标签,他们添加了Windows,Linux和Mac所需的本机库, question中所述。

如果您想了解有关如何创建胖子罐的更多信息,请参阅此doc