错误:缺少 JavaFX 运行时组件,需要使用 JDK 11 运行此应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51478675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:09:14  来源:igfitidea点击:

Error: JavaFX runtime components are missing, and are required to run this application with JDK 11

javaintellij-ideajavafxopenjfx

提问by Maxoudela

I'm trying to run the sample JavaFX project using IntelliJ but it fails with the exception :

我正在尝试使用 IntelliJ 运行示例 JavaFX 项目,但它失败并出现异常:

Error: JavaFX runtime components are missing, and are required to run this application

I have downloaded JDK 11 here : http://jdk.java.net/11/I have downloaded OpenJFX here : http://jdk.java.net/openjfx/I'm using : IntelliJ IDEA 2018.2 (Community Edition) Build #IC-182.3684.40, built on July 17, 2018 JRE: 1.8.0_152-release-1248-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

我在这里下载了 JDK 11:http://jdk.java.net/11/ 我在 这里下载了 OpenJFX:http://jdk.java.net/openjfx/ 我正在使用:IntelliJ IDEA 2018.2(社区版)构建#IC-182.3684.40,构建于 2018 年 7 月 17 日 JRE: 1.8.0_152-release-1248-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains sro Windows 10 10.0

I have created a new JavaFX project in IntelliJ using JDK 11. My JavaFX classes were not known so I have added the OpenJFX library by doing :

我使用 JDK 11 在 IntelliJ 中创建了一个新的 JavaFX 项目。我的 JavaFX 类未知,因此我通过执行以下操作添加了 OpenJFX 库:

  • File -> Project Structure -> Modules -> + -> Library -> Java
  • 文件 -> 项目结构 -> 模块 -> + -> 库 -> Java

I have the OpenJFX added with the 8 jars below "classes" and also the folders below "Sources" and the path to the bin folder under "Native Library Locations".

我在 OpenJFX 中添加了“类”下面的 8 个 jar,还有“源”下面的文件夹和“本机库位置”下 bin 文件夹的路径。

When I'm building the project, it's good, but impossible to run it.

当我构建项目时,它很好,但无法运行它。

What am I doing wrong?

我究竟做错了什么?

回答by Tim V

This worked for me:

这对我有用:

File >> Project Structure >> Modules >> Dependency >> + (on left-side of window)

文件>>项目结构>>模块>>依赖>>+(在窗口左侧)

clicking the "+" sign will let you designate the directory where you have unpacked JavaFX's "lib" folder.

单击“+”号将让您指定解压 JavaFX 的“lib”文件夹的目录。

Scope is Compile (which is the default.) You can then edit this to call it JavaFX by double-clicking on the line.

Scope 是 Compile(这是默认值。)然后您可以编辑它,通过双击该行将其命名为 JavaFX。

then in:

然后在:

Run >> Edit Configurations

运行>>编辑配置

Add this line to VM Options:

将此行添加到 VM 选项:

--module-path /path/to/JavaFX/lib --add-modules=javafx.controls

(oh and don't forget to set the SDK)

(哦,别忘了设置SDK)