perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

NoClassDefFoundError: org/slf4j/LoggerFactory #1159

Open Andromelus opened 4 years ago

Andromelus commented 4 years ago

Version : 2.9.1

Stack trace

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at spark.Service.(Service.java:56) at spark.Spark$SingletonHolder.(Spark.java:51) at spark.Spark.getInstance(Spark.java:55) at spark.Spark.(Spark.java:61) at Api.(Api.java:5) at generator.main(generator.java:61) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ... 6 more

Steps to reproduce

  1. Download the jar from here (2.9.1)
  2. Create a simple class with a simple get: import static spark.Spark.*;
    public class Api {
    public Api() {
        get("test", (req, res) -> "hello, world");
    }
    }
  3. Use the api:

    public static void main(String[] args) throws InterruptedException {
    
        Api api = new Api();

I had to the build path slf4j-simple-1.7.30, still the same problem.

Overview of the config:

image

jbuisine commented 4 years ago

Hello,

I had same issue and I added this slf4j-simple dependency version with spark-core 2.9.1:

<dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.21</version>
</dependency>

Now it seems to work well.

I just followed Spark logger documentation.

Hope it will help you !

viniciusgati commented 3 years ago

why is this a dependency that is not contained? i think the docs should mention it... and just to uipdate add the sl4j dependency only is not solving the problema