【问题标题】:Module 'project' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'模块“项目”从“javafx.base”和“javafx.base”读取包“javafx.beans”
【发布时间】:2021-09-14 20:20:00
【问题描述】:

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

javafx.base reads package javafx.beans

modular java project (IntelliJ IDEA): Module 'com.test' reads package 'javax.xml.bind' from both 'java.xml.bind' and 'java.xml.bind'

Package 'com.example' reads package 'javafx.beans' from both 'javafx.base' and 'javafx.base'

该文件如下所示:

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。

我该如何解决这个问题?

【问题讨论】:

  • 听起来像是一个 Intellij 错误,无法解决一个包含另一个的问题
  • 嗯,这是一个很好的方向。你会建议我搜索什么来了解如何让 Intellij Idea 解决这个问题?

标签: java maven intellij-idea javafx pom.xml


【解决方案1】:

我认为这是一个 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;
}

【讨论】:

  • 这很有帮助,因为这意味着我需要更好地配置 Intellij。我相信在这个项目中使用 Intellij 是可能的,就像这里所说的那样:openjfx.io/openjfx-docs/#maven 你认为你可以让它工作并告诉我你是怎么做到的吗?就像我说的,我对这一切都不熟悉。
  • 我的项目在 IntellJ 中运行良好(我只是为你安装了它)这里是演示项目file.io/M8un2C2tomia
猜你喜欢
  • 2019-05-02
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 2022-01-26
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 2021-01-04
相关资源
最近更新 更多