Linux Mint java 和 JavaFX

use*_*814 5 java installation javafx

我正在运行 Linux Mint 19.1 并安装了 OpenJDK 运行时环境。我没有安装 eclipse 并且这个问题没有提供足够的细节来说明 OP 的问题实际上是什么,尽管标题似乎并不特别相关。

> java --version
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)

自从安装 Java 以来,我还javafx使用我在Ask Ubuntu上找到的信息进行了安装。apt报告如下:

> sudo apt install openjdk-11-jdk openjfx
...
  openjdk-11-jdk is already the newest version (11.0.3+7-1ubuntu2~18.04.1).
  openjfx is already the newest version (11.0.2+1-1~18.04.2).
Run Code Online (Sandbox Code Playgroud)

我现在遇到的问题是该行import javafx;导致以下错误:

> java CheckJavaFX.java
CheckJavaFX.java:1: error: package javafx.application does not exist
import javafx.application.Application;
                     ^
1 error
error: compilation failed
Run Code Online (Sandbox Code Playgroud)

如何解决问题?

Jos*_*eda 2

根据您所做的事情:

sudo apt install openjdk-11-jdk openjfx
Run Code Online (Sandbox Code Playgroud)

您已经安装了两个不同的东西:

  • 一方面,openjdk-11-jdk根据此详细信息安装最新的 JDK 11.0.3 。

  • 另一方面,openjfx按照安装JavaFX 11.0.2 。

If you check the latter, you are just downloading the JavaFX SDK (the JavaFX jars and native libraries) to a given location, but you are not bundling it with the JDK.

This explain the error you get, as the JDK doesn't have any JavaFX module included:

error: package javafx.application does not exist

Even if you try to do a "manual merge", by copying those files to the JDK location, that won't work either.

In order to use JavaFX 11+ directly from the SDK, you have to add the jars to the module-path, like explained in the documentation at https://openjfx.io/openjfx-docs/.

Alternatively you can use Maven or Gradle build tools and the JavaFX plugins, that won't require the SDK, and will use Maven Central to retrieve the JavaFX modules.

Finally, if you sill want to use JavaFX bundled with the JDK (without module-path), you can either download a different distribution that bundles it (there are a few out there), or you can "merge" the JDK and the JavaFX SDK yourself, to produce a custom image that combines both, as explained here: https://openjfx.io/openjfx-docs/#modular, section Custom JDK+JavaFX image.