0

I have a Maven project with the following dependencies in the pom.xml file:

<dependencies>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.7</version>
    </dependency>
</dependencies>

However I'm still getting a "java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory" exception.

I also tried adding

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.20</version>
</dependency>
<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
   <version>1.7.20</version>
</dependency>

But they don't make any difference.

How can I fix this?

The Oddler
  • 6,314
  • 7
  • 51
  • 94
  • Possible duplicate of [NoClassDefFoundError: org/slf4j/LoggerFactory with logback](http://stackoverflow.com/questions/32401726/noclassdeffounderror-org-slf4j-loggerfactory-with-logback) –  May 20 '16 at 14:06
  • I tried adding "slf4j-api" and "slf4j-log4j12", but that doesn't change anything. Shouldn't these be added automatically actually? – The Oddler May 20 '16 at 14:07
  • I use to add `logback-core` also, but that shouldn't be the answer/cause of your problem – superbob May 20 '16 at 14:23
  • Check your dependency jars and see if they have that class or not...you can do this via `mvn dependency:copy-dependencies` then cracking each dependency jar like `jar -tf target/dependency/my-jar-name.jar` ... – rogerdpack Aug 10 '20 at 21:06

1 Answers1

0

Try adding this :

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>

UPDATE This works fine for me. Are you sure isn't there any duplicate or versionational problem in your pom.xml?

<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.2</version>
        </dependency>

UPDATE2

And also i excluded commons-logging in spring definition by the way.

cihan adil seven
  • 541
  • 1
  • 4
  • 20