Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compilation failure: module not found: org.apache.logging.log4j

I have simple application written in Java 11. mvn clean verify (maven 3.6.0) executes with error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project parser: Compilation failure
[ERROR] ...src/main/java/module-info.java:[2,32] module not found: org.apache.logging.log4j  

Dependencies:

<log4j.version>2.11.1</log4j.version>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j.version}</version>
</dependency>

Module-info.java:

module abc {
    requires org.apache.logging.log4j;
}

Log4j2 configuration is default and in .xml file. Usage:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

private static final Logger logger = LogManager.getLogger(Abc.class); 

logger.info("Boom!");

I tried all related questions on stackoverflow with no success.

like image 593
uli Avatar asked Nov 15 '18 19:11

uli


1 Answers

You shall upgrade to the maven-compiler-plugin:3.8.0 and specify the release as 11.

Reason being, on describing the log4j-api.jar using --release 11 states the same name as in your directive.

jar --file=.../.m2/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar --describe-module --release 11
releases: 9

org.apache.logging.log4j jar:file://.../.m2/repository/org/apache/logging/log4j/log4j-api/2.11.1/log4j-api-2.11.1.jar/!META-INF/versions/9/module-info.class
exports org.apache.logging.log4j
exports org.apache.logging.log4j.message
exports org.apache.logging.log4j.simple
exports org.apache.logging.log4j.spi
exports org.apache.logging.log4j.status
exports org.apache.logging.log4j.util
requires java.base mandated
uses org.apache.logging.log4j.message.ThreadDumpMessage$ThreadInfoFactory
uses org.apache.logging.log4j.spi.Provider
uses org.apache.logging.log4j.util.PropertySource

which is primarily because the log4j-api is a modular jar.

On the other hand, log4j-core is derived as an automatic module still which is overridden in its MANIFEST.MF as

org.apache.logging.log4j.core
like image 113
Naman Avatar answered Sep 22 '22 21:09

Naman