java.lang.NoSuchMethodError: org.apache.log4j.Logger
Asked Answered
H

4

6

We use ivy to manage a multi project java application, and recently this error started showing up when we do builds. What's causing this?

Hodge answered 6/5, 2014 at 15:59 Comment(0)
H
7

This was fixed by adding the following line to the end of the dependencies section in ivy.xml:

<dependencies>
         
  <exclude module="log4j-over-slf4j" /> 
</dependencies>

Why was it an issue?

Hodge answered 6/5, 2014 at 16:2 Comment(1)
I have no ivy.xmlCounterpoise
E
3

It looks like the log4j bridge does not implement the full interface for log4j . If you are still using direct log4j calls, you will need both the slf4j bridge jar and the log4j jar

In your case it looks like you excluded the bridge jar, so all slf4j calls go directly to log4j instead of the bridge.

If your code invokes log4j through the xml file , this will work. However if your code programatically invokes log4j initialization this bridge is not going to work

Erratum answered 6/5, 2014 at 16:9 Comment(0)
S
1

I know this is a very old question but I wanted to share what worked out fine for me. If you have different artifacts of slf4j-log4j* for two projects that are interdependent on each other, for example spring data jpa and spring MVC, this happens. Keep it consistent or even better have a parent pom. In my case I had slf4j-log4j12 on my spring data jpa project and slf4j-log4j13 on my spring MVC one.

Stinger answered 14/10, 2017 at 11:28 Comment(0)
S
-2

Comment this dependency from the pom.xml

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>
</dependency>

And add (or keep) the following one:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.12</version>
</dependency>

Wherever you see a compile time error regarding Log4j, add the following import:

import org.apache.log4j.Logger;
Swartz answered 8/8, 2017 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.