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

OpenJDK11搭配JavaFX11在Eclipse运行报错:缺少JavaFX运行时组件

Fixing "JavaFX runtime components are missing" Error in Eclipse with OpenJDK 11 & JavaFX 11

Let's break down what's going wrong and get your JAdaptiveMPC project running smoothly again. The core issues here are version mismatch between your JDK and JavaFX, plus incomplete runtime configuration in Eclipse.


1. Fix the JavaFX Version Mismatch

You're using OpenJDK 11.0.2, but your Maven dependencies are pulling JavaFX 13-ea (Early Access) — this version mismatch is a major source of compatibility issues. JavaFX 13 isn't designed to work seamlessly with JDK 11, so let's switch to JavaFX 11.0.2 to match your JDK version.

Update your pom.xml to use the correct, stable JavaFX 11.0.2 dependencies. Here's a trimmed-down, correct configuration (only include modules your project actually uses — no need to add all unless you need them):

<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>

 <!-- Manage versions centrally to avoid repetition -->
 <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>
        <!-- Add other modules (javafx-graphics, javafx-swing, etc.) only if your project uses them -->
    </dependencies>
 </dependencyManagement>

 <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
    </dependency>
 </dependencies>
</project>

After updating, run mvn clean install in Eclipse (right-click project > Run As > Maven Install) to refresh dependencies.


2. Configure Eclipse's Run Arguments Properly

Even with correct Maven dependencies, Eclipse needs explicit VM arguments to locate the JavaFX runtime. Here's how to set this up:

  • Right-click your project > Run As > Run Configurations
  • Select your Java Application configuration (create one if you don't have it)
  • Switch to the VM Arguments tab
  • Add the following line (replace /path/to/javafx-sdk-11.0.2/lib with the absolute path to your local JavaFX SDK's lib folder):
    --module-path /path/to/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml
    
    • Adjust the --add-modules list to include only the modules your project uses (e.g., add javafx-swing if you need it)
  • Click Apply then Run

If you don't want to use the local SDK, you can use Maven's dependency path, but using the SDK directly is more reliable for runtime resolution.


3. Check Module Configuration (If Using Modules)

If your project uses Java Modules (has a module-info.java file), make sure it declares dependencies on the required JavaFX modules:

module JAdaptiveMPC {
    requires javafx.controls;
    requires javafx.fxml;
    // If you use FXML, open your controller package to javafx.fxml
    opens com.yourpackage.controllers to javafx.fxml;
    // Export your main class package if needed
    exports com.yourpackage.main;
}

If you're not using modules, you can skip this step — just ensure your main class extends javafx.application.Application correctly.


4. Verify Your Main Class Setup

Double-check that your main class is structured properly. For JavaFX apps, it should look something like this:

package com.yourpackage.main;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("JAdaptiveMPC");
        primaryStage.setScene(new Scene(new Label("Hello JavaFX!"), 300, 200));
        primaryStage.show();
    }

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

Make sure the launch(args) method is called — this triggers the JavaFX runtime initialization.


After following these steps, your project should compile and run without the "runtime components missing" error. The key fixes are matching JavaFX to your JDK version and configuring Eclipse to point to the JavaFX runtime via VM arguments.

内容的提问来源于stack exchange,提问作者euraad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 05:23:35