5

我有一个 JavaFx 项目,其中Maven install不断给我错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project gui: Compilation failure: Compilation failure:
[ERROR] /C:/Users/digit/eclipse-workspace/gsn-notator/gui/src/main/java/gui/AppController.java:[21,19] package javafx.fxml does not exist
[ERROR] /C:/Users/digit/eclipse-workspace/gsn-notator/gui/src/main/java/gui/AppController.java:[29,17] cannot find symbol
[ERROR] symbol:   class FXMLLoader
[ERROR] location: class gui.AppController
[ERROR] /C:/Users/digit/eclipse-workspace/gsn-notator/gui/src/main/java/gui/AppController.java:[29,45] cannot find symbol
[ERROR] symbol:   class FXMLLoader
[ERROR] location: class gui.AppController

我究竟做错了什么?我如何说服 Maven/Eclipse/Java/Whatever 找到FXMLLoader?

项目结构有两个模块,gui本教程logic中的项目结构相同。我的整体项目 pom 是:

<modules>
    <module>logic</module>
    <module>gui</module>
</modules>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>6.2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

gui模块的 pom 是:

<parent>
    <groupId>com.gmail.digitig</groupId>
    <artifactId>gsn-notator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>gui</artifactId>
<dependencies>
    <dependency>
        <groupId>com.gmail.digitig</groupId>
        <artifactId>logic</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>  
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11-ea+19</version>
    </dependency>
</dependencies>

除了微不足道的module_info.java. 报告错误的Classgui.AppController是:

package gui;

import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.BorderPane;

public class AppController extends BorderPane {
public AppController() {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("App.fxml"));
    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}

}

4

1 回答 1

12

您需要javafx-fxml在您的pom.xml

<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11.0.1</version>
</dependency>

并确保module-info.java有一个模块requires指令javafx.fxml

requires javafx.fxml;

其他建议:

于 2018-11-18T02:09:54.867 回答