简体   繁体   English

Linux Mint java和JavaFX

[英]Linux Mint java and JavaFX

I am running Linux Mint 19.1 and have installed the OpenJDK Runtime Environment. 我正在运行Linux Mint 19.1并安装了OpenJDK Runtime Environment。 I do not have eclipse installed and this question , which does not provide sufficient detail to make it clear what OP's question actually is, doesn't seem particularly relevant despite the title. 我没有安装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)

Since installing Java, I have also installed javafx using the information I found on Ask Ubuntu . 自从安装Java以来​​,我还使用在Ask Ubuntu上找到的信息安装了javafx apt reports the following: 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).

The problem I am now having is that the line import javafx; 我现在遇到的问题是行import javafx; results in the following error: 导致以下错误:

> java CheckJavaFX.java
CheckJavaFX.java:1: error: package javafx.application does not exist
import javafx.application.Application;
                     ^
1 error
error: compilation failed

How do I resolve the problem? 我该如何解决这个问题?

Based on what you have done: 根据您的所作所为:

sudo apt install openjdk-11-jdk openjfx

You have installed two different things: 你安装了两件不同的东西:

  • On one side, openjdk-11-jdk installs the latest JDK 11.0.3, based on this detail . 一方面, openjdk-11-jdk根据这个细节安装最新的JDK 11.0.3。

  • On the other, openjfx installs JavaFX 11.0.2 according to this . 另一方面, 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. 如果你检查后者,你只是将JavaFX SDK(JavaFX jar和本机库)下载到给定位置,但是你没有将它与JDK捆绑在一起。

This explain the error you get, as the JDK doesn't have any JavaFX module included: 这解释了您得到的错误,因为JDK没有包含任何JavaFX模块:

error: package javafx.application does not exist 错误:包javafx.application不存在

Even if you try to do a "manual merge", by copying those files to the JDK location, that won't work either. 即使您尝试执行“手动合并”,通过将这些文件复制到JDK位置,也无法正常工作。

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/ . 要直接从SDK使用JavaFX 11+,您必须将jar添加到模块路径,如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. 或者,您可以使用不需要SDK的Maven或Gradle构建工具和JavaFX插件,并使用Maven Central来检索JavaFX模块。

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. 最后,如果您希望使用与JDK捆绑的JavaFX(没有模块路径),您可以下载捆绑它的不同发行版(其中有一些),或者您可以“合并”JDK和JavaFX SDK本身,生成一个结合两者的自定义图像,如下所述: https//openjfx.io/openjfx-docs/#modular ,自定义JDK + JavaFX图像部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM