You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ中JavaFX+Gradle项目启动报错:JavaFX runtime components are missing 求助

Troubleshooting Your JavaFX + Gradle Project

Hey there! Let's work through fixing your JavaFX + Gradle setup step by step. Based on the configs you shared, here are the key adjustments and checks to get your app running:

1. Fix Missing JavaFX Dependency & Clean Up Module Info

Looking at your files:

  • Your module-info.java declares a dependency on javafx.fxml, but your Gradle build doesn't include this module in dependencies. This will cause runtime errors when the module system can't resolve the dependency.
  • requires java.base is redundant—every Java module automatically depends on java.base, so you can remove this line.

Updated module-info.java:

module com.skb {
    requires javafx.fxml;
    requires javafx.controls;
    requires javafx.graphics;

    opens com.skb;
}

2. Simplify Gradle Configuration with Official JavaFX Plugin

Your custom getJavaFXPlatform() method uses an internal Gradle API (DefaultNativePlatform), which can break across Gradle versions. Instead, use the official OpenJFX Gradle plugin—it handles platform-specific dependencies automatically, eliminating the need for custom OS detection.

Updated build.gradle:

plugins {
    id 'application'
    // Use official OpenJFX plugin to manage JavaFX dependencies
    id 'org.openjfx.javafxplugin' version '0.0.10'
}

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

repositories {
    mavenCentral()
}

// Configure JavaFX via the plugin
javafx {
    version = "15.0.1"
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.graphics']
}

application {
    mainModule.set('com.skb')
    mainClass.set('com.skb.EditorApp')
}

java {
    modularity.inferModulePath.set(true)
}

3. Verify IntelliJ Run Configuration

When running modular JavaFX apps with Gradle, always use the Gradle task instead of directly running the EditorApp class:

  1. Open the Gradle tool window in IntelliJ (right sidebar).
  2. Navigate to Tasks > application > run.
  3. Right-click the run task and select "Run" to launch your app.

Directly running the class can cause module path resolution issues, as IntelliJ may not properly inject Gradle-managed dependencies into the module path.

4. Test the Setup

After making these changes:

  1. Click the "Refresh Gradle Project" button in the Gradle tool window to sync your config.
  2. Run the application:run task—you should see the "Running..." output in the console if everything works correctly.

内容的提问来源于stack exchange,提问作者Sourav Kannantha B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 23:23:12