Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory using logback-classic

when running my program after building it like this mvn clean install then running it with java -jar target/Sorting-1.0-SNAPSHOT.jar. I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at xyz.skwar.sorting.Main.<clinit>(
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
    at java.base/java.lang.ClassLoader.loadClass(
    ... 1 more

I researched it myself by reading this articel, it is not related since it has to do with a dependency. I read the following stack overflow posts:

Those all did not fix the problem since I am including the logging libary not just the api, I tried the solution from the 4th one but also did not work. The 5th one also is not relevant since I am not setting a scope. When I remove the slf4j-api it fails with, even though acording to the slf4j docs logback-classic provides slf4j-api:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.

And I also made I minimal code sample which still has the problem:

package xyz.skwar.sorting;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
  private static final Logger logger = LoggerFactory.getLogger(Main.class);

  public static void main(String[] args) {"test");

And here is also the entire pom.xml file:

<project xmlns=""


      <name>Central Repository</name>
        <!-- Build an executable JAR -->


  • There are two steps to create a fat jar using manual maven configuration.

    1. Copy dependencies under libs directory (Missing in your pom)
    2. Create executable jar and specify classpath as libs directory. (You are already doing this.)

    So use maven-dependency-plugin to copy the dependencies under libs directory and then it should work fine.