错误:缺少 JavaFX 运行时组件。构建 javafx 应用程序时

这是我的第一个 javafx 和 gradle 应用程序。首先,我在 IntelliJ 中创建了一个 gradle 项目,然后我添加了参考 this 教程的 JavaFX 依赖项。我的 gradle 文件如下所示:

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

plugins {
    id 'application'
}

group 'com.skb'
version '1.0-snAPSHOT'

repositories {
    mavenCentral()
}

def javaFXPlatform = getJavaFXPlatform()
def javaFXVersion = "15.0.1"

dependencies {
    // you need a dependency for each of the JavaFX modules you're going to use
    implementation "org.openjfx:javafx-base:${javaFXVersion}:${javaFXPlatform}"
    implementation "org.openjfx:javafx-controls:${javaFXVersion}:${javaFXPlatform}"
    implementation "org.openjfx:javafx-graphics:${javaFXVersion}:${javaFXPlatform}"
}

application {
    //Java Module System module name
    mainmodule.set('com.skb')
    //Your JavaFX application class
    mainClass.set('com.skb.EditorApp')
}

java {
    // this enables Java Modularity in Gradle (version 6.7 and above)
    modularity.inferModulePath.set(true)
}

// Based on this StackOverflow answer: https://stackoverflow.com/a/65209664/653519
private static String getJavaFXPlatform() {
    def currentOS = DefaultNativePlatform.currentOperatingSystem
    if (currentOS.isWindows()) {
        return 'win'
    } else if (currentOS.isLinux()) {
        return 'linux'
    } else if (currentOS.isMacOsX()) {
        return 'mac'
    }
    return null
}

我的 module_info.java 看起来像这样:

module com.skb {

    requires javafx.fxml;
    requires javafx.controls;
    requires javafx.graphics;
    requires java.base;
    //requires org.fxmisc.richtext;
    //requires org.json;

    opens com.skb;
}

EditorApp 类只包含一些 biolerplate 代码:

package com.skb;

import javafx.application.Application;
import javafx.stage.Stage;

public class EditorApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        System.out.println("Running...");
    }

    public static void main(String[] args) {
        launch(args);
    }
}

项目结构是这样的:

错误:缺少 JavaFX 运行时组件。构建 javafx 应用程序时

我使用的是 IntelliJ 2021.1 社区版。

请帮帮我。我已经对这个错误进行了大量搜索,但没有解决该错误。

qpqp78952 回答:错误:缺少 JavaFX 运行时组件。构建 javafx 应用程序时

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/9731.html

大家都在问