gpt4 book ai didi

java - Maven 找不到 FXMLLoader

转载 作者:行者123 更新时间:2023-11-30 07:43:35 25 4
gpt4 key购买 nike

我有一个 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

工程结构有guilogic两个模块,工程结构在this tutorial .我的整体项目 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。报错的gui.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);
}
}

最佳答案

您需要包含 javafx-fxml 的依赖项在你的 pom.xml 中:

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

并确保 module-info.java 具有用于 javafx.fxml 模块的 requires 指令。

requires javafx.fxml;

其他建议:

关于java - Maven 找不到 FXMLLoader,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53357207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com