Using log4j-1.2-api but log4j1.x classes are not found

Viewed 3204

as described by Apache

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.9.1</version>
  </dependency>
</dependencies>

However, I'm still seeing an error when trying to import

import org.apache.log4j.Logger;

According to Apache, this should work?

https://logging.apache.org/log4j/2.x/maven-artifacts.html

Thanks

2 Answers

You have to put both dependencies in pom.xml:

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

and import should be:

import org.apache.logging.log4j.Logger;

A maven dependency requires a type but the example given by Apache for the bridge API here specifies 'bundle': https://logging.apache.org/log4j/2.0/log4j-1.2-api/dependency-info.html

If I do that then I don't get log4j-1.2-api.jar in my dependencies, if I set the type to 'jar' then I do get the jar and the log4j-api-2.9.1.jar and can import org.apache.log4j.

Related