在 IDEA 环境下导入了 JAVAFX 的包,但总是提示: 缺少 JavaFX 运行时组件, 需要使用该组件来运行此应用程序

最近想尝试使用 Java 11 和 JavaFX 11, 但是在使用 IDEA 构建项目的时候,写下以下代码却为报出 错误: 缺少 JavaFX 运行时组件, 需要使用该组件来运行此应用程序

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
        var s = "ssad";

    }


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

尝试使用了 openjfx教程中的 pom 文件来构建,构建完还还缺少了 javafx.fxml JAR 包。运行,还是出现以前的错误。
  可以看这篇文章试试能否正确启动,当然要查到新技术的答案最好的方式还是在google中用英语来描述问题:
Building OpenJFX

猜你喜欢

转载自blog.csdn.net/weixin_40589493/article/details/82826023
今日推荐