java.lang.NoClassDefFoundError:org / slf4j / Logger

时间:2018-03-24 01:34:28

标签: java logging classnotfoundexception

我正在尝试运行使用Logger类的项目。尝试这样做会导致下面的例外。编译器正在org / slf4j / Logger中查找Logger但是在我的库中它位于org / apache / log4j(我正在使用IntelliJ)。我该如何解决这个问题?

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:42)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:455)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:441)
    at activitystreamer.Client.<clinit>(Client.java:17)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

1 个答案:

答案 0 :(得分:0)

您错过了添加SLF4J。要将SLF4j添加到项目中,首先要在SLF4j API中添加。查看https://www.slf4j.org/docs.html了解更多详情。