【问题标题】:Maven can't find FXMLLoaderMaven 找不到 FXMLLoader
【发布时间】:2019-04-20 18:49:24
【问题描述】:

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

}

【问题讨论】:

标签: java maven javafx java-11 openjfx


【解决方案1】:

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

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

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

requires javafx.fxml;

其他建议:

【讨论】:

猜你喜欢
  • 2019-09-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-07
  • 2021-02-14
  • 2019-05-27
  • 2020-12-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多