Error with Slf4j and classpath

2019-09-19 06:39发布

I would execute a maven project but my classpath is not correct... I tried many possibilities without find any solution. The compilation is successfull, but when I start the program, I have this following error :

 [root@sandbox kafka-log-appender]# java -cp "target/kafka-log-appender-1.0-SNAPSHOT.jar:log4j-1.2.17.jar" com.log.kafka.RogueApplication
    Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
            at com.log.kafka.RogueApplication.<clinit>(RogueApplication.java:11)
    Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
            at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
            ... 1 more

Thanks

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-19 06:58

Add slf4j.jar given in the below path:

http://www.java2s.com/Code/JarDownload/slf4j/slf4j.jar.zip

If the issue is not solved try with other slf4j jars suggested in the same page.

查看更多
forever°为你锁心
3楼-- · 2019-09-19 07:05

Look for slf4j-api.jar and any slf4j jar that references log4j and add those as well. There are two or three drivers for log4j. I don't know which one Kafka ships with, but if you see multiple, only put one on there as multiple can make slf4j have problems.

查看更多
登录 后发表回答