kafka NoClassDefFoundError: org/apache/log4j/Lev异常

启动kafka时,报错”Failed to instantiate SLF4J LoggerFactory..Reported exception:..

java.lang.NoClassDefFoundError: org/apache/log4j/Level”,详细日志如下

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
 at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
 at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:107)
 at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:295)
 at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
 at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281)
 at org.apache.kafka.clients.producer.KafkaProducer.<clinit>(KafkaProducer.java:125)
 at com.xwood.test.kafka.KafkaProducerTest.main(KafkaProducerTest.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
 at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 ... 7 more 

解决方法:

第一步:下载log4j-1.2.14.jar.zip依赖包:http://www.xwood.net/search-jar/?q=log4j

第二步:解压log4j-1.2.14.jar.zip,将log4j-1.2.14.jar拷贝到 kafka(你的kafka文件目录)/libs/ 目录下,重新启动kafka即可大功告成!

参考文章:解决运行kafka客户端报”java.lang.NoClassDefFoundError: org/apache/log4j/Level”异常日志t/5870/5874/t_c279707.html

一个关于kafka运行的小问题,但是网上解决方法很难找到,这里和大家分享一下。

    原文作者:妙想
    原文地址: https://zhuanlan.zhihu.com/p/68655504
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞