本文介绍了无法在macOS上执行JavaFX示例:找不到工具包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试启动JavaFX"Hello world"示例时,找不到本机库-否则,它们将被拒绝.症状是未找到工具箱"异常.在某些时候提到了签名,因此macOS似乎有一些特殊性.

When trying to launch the JavaFX "Hello world" sample, the native libraries are not found -- or, they are rejected. The symptom is a "No toolkit found" exception. There seems to be some specificity to macOS, as signing is mentioned at some point.

我所做的(在macOS 10.14.6上):

What I did (on macOS 10.14.6):

  1. https://adoptopenjdk.net
  2. 安装Java 12
  3. http://gluonhq下载了适用于macOS的JavaFX 12 SDK. .com/download/javafx-12-0-2-sdk-mac .将其解压缩为$WRK_DIR/javafx-sdk-12.0.2
  4. https://github.com/openjfx/samples.将其解压缩为$WRK_DIR/samples-master
  1. Installed Java 12 from https://adoptopenjdk.net
  2. Downloaded the JavaFX 12 SDK for macOS from http://gluonhq.com/download/javafx-12-0-2-sdk-mac. Unzipped it as $WRK_DIR/javafx-sdk-12.0.2
  3. Downloaded the JavaFX "hello world" sample from https://github.com/openjfx/samples. Unzipped it as $WRK_DIR/samples-master

然后,我按照入门指南(此处此处).我选择了最简单的路径:没有IDE,没有像Maven这样的构建系统,没有模块化的应用程序,仅是纯CLI.

Then I followed the instructions of the Getting Started (here or here). I chose the simplest path: no IDE, no build system like Maven, non-modular app, nothing but plain CLI.

$ WRK_DIR=$(pwd)
$ ls -lF
total 0
drwxr-xr-x@ 4 bruno  staff  128 19 jul 16:25 javafx-sdk-12.0.2/
drwxr-xr-x@ 8 bruno  staff  256 31 jul 10:18 samples-master/
$ PATH_TO_FX=$WRK_DIR/javafx-sdk-12.0.2/lib
$ ls $PATH_TO_FX
javafx-swt.jar      javafx.properties   libglib-lite.dylib  libjfxwebkit.dylib
javafx.base.jar     javafx.swing.jar    libgstreamer-lite.dylib libprism_common.dylib
javafx.controls.jar javafx.web.jar      libjavafx_font.dylib    libprism_es2.dylib
javafx.fxml.jar     libdecora_sse.dylib libjavafx_iio.dylib libprism_sw.dylib
javafx.graphics.jar libfxplugins.dylib  libjfxmedia.dylib   src.zip
javafx.media.jar    libglass.dylib      libjfxmedia_avf.dylib
$ javac -version
javac 12.0.2
$ cd samples-master/CommandLine/Non-modular/CLI/hellofx
$ javac --module-path $PATH_TO_FX --add-modules=javafx.controls -d out $(find src -name "*.java")
$ find . -type f
./out/hellofx/HelloFX.class
./out/hellofx/Launcher.class
./src/hellofx/HelloFX.java
./src/hellofx/Launcher.java

直到尝试启动为止:

$ java -version
openjdk version "12.0.2" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 12.0.2+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 12.0.2+10, mixed mode)
$ java --module-path $PATH_TO_FX --add-modules=javafx.controls -cp out hellofx.HelloFX
Graphics Device initialization failed for :  es2, sw
Error initializing QuantumRenderer: no suitable pipeline found
   <stack trimmed>
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
   <stack trimmed>
Exception in thread "main" java.lang.reflect.InvocationTargetException
   <stack trimmed>
Caused by: java.lang.RuntimeException: No toolkit found
   <stack trimmed>

我所做的研究使我认为找不到本地库.因此,我尝试将$PATH_TO_FX添加到LD_LIBRARY_PATHDY LD_LIBRARY_PATH中,但没有更好的结果.在此评论之后,我在其中添加了-Dprism.verbose=true命令行:

The research I did led me to think that the native libraries are not found. So I tried to add $PATH_TO_FX to LD_LIBRARY_PATH and DY LD_LIBRARY_PATH with no better result. Following this comment I added -Dprism.verbose=true to the command line:

$ java -Dprism.verbose=true --module-path $PATH_TO_FX --add-modules=javafx.controls -cp out hellofx.HelloFX
Prism pipeline init order: es2 sw
Using Double Precision Marlin Rasterizer
Using dirty region optimizations
Not using texture mask for primitives
Not forcing power of 2 sizes for textures
Using hardware CLAMP_TO_ZERO mode
Opting in for HiDPI pixel scaling
Prism pipeline name = com.sun.prism.es2.ES2Pipeline
Loading ES2 native library ... prism_es2
GraphicsPipeline.createPipeline failed for com.sun.prism.es2.ES2Pipeline
java.lang.UnsatisfiedLinkError: no prism_es2 in java.library.path: [/Users/bruno/Library/Java/Extensions, /Library/Java/Extensions, /Network/Library/Java/Extensions, /System/Library/Java/Extensions, /usr/lib/java, .]
   <trimmed the rest of errors that are essentially the above>

因此确实存在(至少)没有找到libprism_es2.dylib的问题.然后,我尝试将$PATH_TO_FX添加到java.library.path:

So indeed there is a problem of (at least) libprism_es2.dylib not being found. I then tried to add $PATH_TO_FX to java.library.path:

$ java -Dprism.verbose=true -Djava.library.path=$PATH_TO_FX --module-path $PATH_TO_FX --add-modules=javafx.controls -cp out hellofx.HelloFX
Prism pipeline init order: es2 sw
Using Double Precision Marlin Rasterizer
Using dirty region optimizations
Not using texture mask for primitives
Not forcing power of 2 sizes for textures
Using hardware CLAMP_TO_ZERO mode
Opting in for HiDPI pixel scaling
Prism pipeline name = com.sun.prism.es2.ES2Pipeline
Loading ES2 native library ... prism_es2
GraphicsPipeline.createPipeline failed for com.sun.prism.es2.ES2Pipeline
java.lang.UnsatisfiedLinkError: /Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib: dlopen(/Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib, 1): no suitable image found.  Did find:
    /Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib: code signature in (/Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
   <...>

现在已找到该库,但认为该库无效.

Now the library is found, but is not considered valid.

推荐答案

在您的命令行中:

$ java -Dprism.verbose=true --module-path $PATH_TO_FX \
    --add-modules=javafx.controls -cp out hellofx.HelloFX

一切看起来都不错,因此应该可以正常工作.实际上,您可以运行它,直到失败并显示以下信息:

everything looks okay, so it should work fine. In fact, you get it running, until it fails with:

GraphicsPipeline.createPipeline failed for com.sun.prism.es2.ES2Pipeline
java.lang.UnsatisfiedLinkError: /Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib: \
    dlopen(/Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib, 1): no suitable image found.  \
    Did find: /Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib: \
code signature in (/Users/bruno/try/javafx-sdk-12.0.2/lib/libprism_es2.dylib) \
not valid for use in process using Library Validation: \
mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

有一个错误报告给AdoptOpenJDK 11.0.4有关本机库的信息在Mac上无法用11.0.4 + 11.2加载,并且会产生完全相同的错误消息.

There is a bug reported to AdoptOpenJDK 11.0.4 about native libraries that cannot be loaded with 11.0.4+11.2 on Mac, and produces the exact same error message.

但是,您正在运行AdoptOpenJDK 12.0.2,并且您的项目可以使用 OpenJDK 12 ,因此似乎此错误也扩展到了AdoptOpenJDK 12.0.2 + 10.

However, you are running AdoptOpenJDK 12.0.2, and your project works for you with OpenJDK 12, so it seems this bugs also extends to AdoptOpenJDK 12.0.2+10.

因此,在解决此问题后,您可以使用OpenJDK12.请注意,已经报告 12个失败.

So while this is fixed, you can use OpenJDK 12. Note that there has been already reported that 12 fails.

编辑

我可以确认最新的适用于Mac的11个预发行版(实际上说的是Java版本11.0.5).

I can confirm that the latest 11 prerelease for Mac works (it actually says Java version 11.0.5).

最新的 12个预发行版(适用于Mac),效果很好.

The same goes with the latest 12 prerelease for Mac, it works fine.

这篇关于无法在macOS上执行JavaFX示例:找不到工具包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:53