简体   繁体   English

错误:缺少 JavaFX 运行时组件 - JavaFX 11 和 OpenJDK 11 以及 Eclipse IDE

[英]Error: JavaFX runtime components are missing - JavaFX 11 and OpenJDK 11 and Eclipse IDE

I have this classical issue: Using JavaFX 11 with OpenJDK 11 together with Eclipse IDE.我有这个经典问题:将 JavaFX 11 与 OpenJDK 11 与 Eclipse IDE 一起使用。

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

I have OpenJDK 11.0.2我有 OpenJDK 11.0.2

dell@dell-pc:~$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
dell@dell-pc:~$ 

And I also have JavaFX 11 SDK .而且我还有JavaFX 11 SDK By the way.顺便一提。 I'm using Lubuntu Linux 18.10 if you wonder.如果您想知道,我正在使用 Lubuntu Linux 18.10。 在此处输入图像描述

Then I have included the .jar files from the JavaFX 11 SDK in Eclipse IDE into a library package.然后,我将 Eclipse IDE 中JavaFX 11 SDK中的.jar文件包含到一个库包中。

在此处输入图像描述

Then I have included this library package into my JAdaptiveMPC project.然后我将这个库包包含到我的JAdaptiveMPC项目中。 在此处输入图像描述

I get no error in my code syntax, but still, I cannot compile my project.我的代码语法没有错误,但仍然无法编译我的项目。 在此处输入图像描述

Do you know why?你知道为什么吗? I got the same error if I import all those .jar files from Maven instead of download the JavaFX SDK and import it into a library.如果我从 Maven 导入所有这些.jar文件而不是下载JavaFX SDK并将其导入到库中,我会遇到同样的错误。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Control</groupId>
  <artifactId>JAdaptiveMPC</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx</artifactId>
        <version>13-ea+5</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-base</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>13-ea+5</version>
    </dependency>
  </dependencies>
</project>

Continue继续

I have added this in the Run Configuration我在Run Configuration中添加了这个

在此处输入图像描述

And then I try to run然后我试着跑在此处输入图像描述

Still errors.还是错误。

Your problem is not compiling the project, but running it.您的问题不是编译项目,而是运行它。 Since your main is defined in your Application -extension, running the project will require JavaFX in your module path on startup.由于您的main是在您的Application扩展中定义的,因此运行该项目将需要在启动时在您的模块路径中使用 JavaFX。

So either outsource your main into a class different from your Application or add the JavaFX modules with VM arguments:因此,要么将main外包到与Application不同的类中,要么添加带有 VM 参数的 JavaFX 模块:

--module-path="<javafx-root>\lib" --add-modules="javafx.base,javafx.controls,javafx.media,…"

See this for some more info.请参阅以获取更多信息。

The question is old but this how it did work for me in intellij(linux):这个问题很老,但这在 intellij(linux) 中对我有用:

1- go to run -> edit configurations 1- 去运行 -> 编辑配置

2- add the path in VM Options: 2- 在 VM 选项中添加路径:

--module-path yourpath/lib --add-modules javafx.controls,javafx.fxml --module-path yourpath/lib --add-modules javafx.controls,javafx.fxml

在此处输入图像描述

In eclipse I selected this MODULE PATH option from the dropdown and it worked for me - I didnt need the vm agruments.在 eclipse 中,我从下拉列表中选择了这个 MODULE PATH 选项,它对我有用——我不需要 vm agruments。 Make sure the JavaFx Jars are added in the ModulePath under Dependencies Tab (Eclipse >> Project >> Configurations)确保将 JavaFx Jars 添加到 Dependencies 选项卡下的 ModulePath 中(Eclipse >> Project >> Configurations)

I was working on Eclipse.我正在研究 Eclipse。 For me, running the class with the below VM arguments worked:对我来说,使用以下 VM 参数运行该类有效:

-p C:\<your_path>\javafx-sdk-11\lib --add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media,javafx.web --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED --add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED
-Djava.library.path="C:\<your_path>\javafx-sdk-11\bin"

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

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