首页 > 解决方案 > 错误:缺少 JavaFX 运行时组件,需要运行此应用程序(使用 Maven)

问题描述

Error: JavaFX runtime components are missing, and are required to run this application当我尝试编译 JavaFX 应用程序时,IDEA中出现错误。我通过 maven 添加了模块。有 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
    <artifactId>clockAlarm</artifactId>
    <version>1.0-SNAPSHOT</version>

    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.5</version>
                <configuration>
                    <mainClass>Program</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

如果我只想通过 maven 使用 JavaFX 模块而不下载 sdk 并自行设置,如何解决?

有Programm类:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.text.Text;

public class Program extends Application {

    public static void main(String[] args) {

        Application.launch(args);
    }

    public void start(Stage stage) {

        Text text = new Text("Alarm Clock");
        text.setLayoutY(80);
        text.setLayoutX(100);

        Group group = new Group(text);

        Scene scene = new Scene(group);
        stage.setScene(scene);
        stage.setTitle("alarmClock");
        stage.setWidth(300);
        stage.setHeight(250);
        stage.show();
    }
}

所有项目设置都设置为 13 java 版本。

标签: javamavenjavafx

解决方案


推荐阅读