首页 > 解决方案 > 模块“项目”从“javafx.base”和“javafx.base”读取包“javafx.beans”

问题描述

标题中的错误是我的 module-info.java 中的错误。我是Java新手,所以我希望你给出答案时我能理解你的答案。我在这里找到了提出相同问题的其他问题,他们可能有答案,我只是不明白如何将其应用于我的情况。

javafx.base 读取包 javafx.beans

模块化java项目(IntelliJ IDEA):模块“com.test”从“java.xml.bind”和“java.xml.bind”读取包“javax.xml.bind”

包“com.example”从“javafx.base”和“javafx.base”中读取包“javafx.beans”

这是该文件的样子:

module project{
    requires javafx.controls;
    requires javafx.fxml;
    requires sikulixapi;

    opens com.example to javafx.fxml;

    exports com.example;
}

当我注释掉两个 javafx.* require 行时,错误就消失了。

我正在使用 Intellij Idea,我创建了一个 Javafx 项目并添加了 Maven。

我将如何去寻找解决这个问题的方法?

标签: javamavenintellij-ideajavafxpom.xml

解决方案


我认为这是一个 Intellj 问题。我在 Eclipse 中创建了 Hello World JavaFX 示例并且没有问题。

pom.xml

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>demo</groupId>
    <artifactId>hello</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml </artifactId>
            <version>17-ea+14</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>demo.hello.App</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

模块信息.java

module demo.hello {
    requires javafx.controls;
    requires javafx.fxml;
    exports demo.hello;
}

推荐阅读