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

2022-09-03 13:10:10

我有一个经典的问题:将JavaFX 11与OpenJDK 11一起使用以及Eclipse IDE。

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

我有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:~$ 

我也有.顺便一提!如果你想知道,我正在使用Lubuntu Linux 18.10。JavaFX 11 SDKenter image description here

然后,我将 Eclipse IDE 中的文件包含在库包中。.jarJavaFX 11 SDK

enter image description here

然后,我已将此库包包含在我的项目中。JAdaptiveMPCenter image description here

我的代码语法中没有错误,但是我仍然无法编译我的项目。enter image description here

你知道为什么吗?如果我从Maven导入所有这些文件,而不是下载并将其导入到库中,我得到了同样的错误。.jarJavaFX 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>

继续

我已将其添加到Run Configuration

enter image description here

然后我试着跑enter image description here

仍然有错误。


答案 1

您的问题不在于编译项目,而在于运行它。由于 您的 是在 -extension 中定义的,因此运行项目将需要在启动时在模块路径中使用 JavaFX。mainApplication

因此,要么将你外包到一个与你不同的类中,要么添加带有VM参数的JavaFX模块:mainApplication

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

有关详细信息,请参阅此处


答案 2

这个问题已经很老了,但它在intellij(linux)中是如何工作的:

1- 转到运行 ->编辑配置

2- 在虚拟机选项中添加路径:

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


推荐