Netbeans + Java 9 个模块 + Log4j 2.11 = 未找到模块

Netbeans + Java 9 Modules + Log4j 2.11 = Module not found

我使用 Apache Netbeans 9 Beta 9(2018 年 2 月 22 日)。我有一个 Java 9 模块应用程序。我想将 Log4j 2 集成到我的应用程序中。这是我的 modile-info.java.

module ru.itlect.remka.agent {

    exports ru.itlect.remka.agent;

    requires ru.itlect.remka.commons;
    requires org.apache.logging.log4j.core;
    requires org.apache.logging.log4j;

    requires static spring.context;
    requires java.logging;
    requires java.xml;
    requires java.sql;
    requires java.desktop;
    requires java.naming;
    requires java.rmi;

    requires static javafx.graphics;
    requires static javafx.controls;
}

Netbeans 说找不到 org.apache.logging.log4j 模块。 虽然 org.apache.logging.log4j.core 没问题。当我构建项目时,它构建成功。所以问题出在 Netbeans 本身。 java --list-modules 表示 org.apache.logging.log4jlog4j-api-2.11.0.jar 中。 如果我键入 requeres log,Netbeans 会建议 log4j.api,其中 log4j-api-2.11.0.jar 的自动模块名称。以为 Netbeans 说 log4j.api 也找不到。

我可以忍受模块-info.java 中不断出现的错误消息,但是 Netbeans 在 log4j-api-2.11.0.jar 中看不到任何 class,所以我在任何 class 中都有错误使用记录器。 如何让Netbeans看到模块?

这是我的一部分 pom.xml:

<dependencies>

    <!-- Ремка -->
    <dependency>
        <groupId>ru.itlect.remka</groupId>
        <artifactId>commons</artifactId>
        <version>1.0.0</version>
    </dependency>

    <!--Spring-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.0.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>5.0.6.RELEASE</version>
    </dependency>

    <!-- Аннотации -->
    <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.5</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- Logs -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.0</version>
    </dependency>
</dependencies>

我在更新某些应用程序以使用 Log4j2 V2.11.1 作为模块时也遇到了问题。我创建了一个简单的测试用例并将其提交到 Netbeans 用户邮件列表。

截至今天早些时候,已发现并修复了最新版本的 Netbeans 9 中的一个错误。 Pull request 941, which Geertjan approved this morning, explains. The mailing list (users@netbeans.incubator.apache.org) contains suggestions for working around the problem ahead of the fix being merged into a new release. A new release is entering the NetCAT (Community Acceptance Testing) 进程。开发人员将感谢社区帮助更快地完成它,这可能是最好的前进方式。

如果您需要立即解决方案,讨论中建议的一种方法是编辑 jar 文件以将 module-info.class 文件移动到根结构中。