Search code examples
javamavennetbeanslog4jjava-9

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


I use Apache Netbeans 9 Beta 9 (22 February 2018). I have a Java 9 Module application. And I want to integrate Log4j 2 into my application. Here is my 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 says that org.apache.logging.log4j module is not found. Though org.apache.logging.log4j.core is OK. When I build the project, it is built successfully. So the problem is in Netbeans itself. java --list-modules says that the org.apache.logging.log4j is in log4j-api-2.11.0.jar. If I type requeres log Netbeans suggests log4j.api which the automatic module name for log4j-api-2.11.0.jar. Thought Netbeans says that log4j.api is ot found either.

I can live with the constant error message in module-info.java, but Netbeans cannot see any class in log4j-api-2.11.0.jar so I have errors in any class which uses loggers. How to make Netbeans see the module?

This is a part from my 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>

Solution

  • I too was having trouble updating some applications to use Log4j2 V2.11.1 as a module. I created a simple test case and raised it on the Netbeans users mailing list.

    As of earlier today, a bug in the latest release of Netbeans 9 was found and fixed. 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) process. The developers would appreciate community help to finish it faster, which is probably the best way forward.

    If you need an immediate solution, one suggested approach from the discussion is to edit the jar file to move the module-info.class file into the root structure.