Java NoClassDefFoundError: org/slf4j/Logger

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26458806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:33:14  来源:igfitidea点击:

NoClassDefFoundError: org/slf4j/Logger

javalogginglog4jslf4jlog4j2

提问by Stephen McKain

I added Log4J2 to my application. I copied all the Log4J2 .jar files to by LIB directory and created the Log4J2.xml file to support it. My code was updated to import the necessary Log Manager and Logger APIs. I then added the static final logger method and called the logger apis in my code. Everything compiled file in Eclipse. I proceed to start my server on my DEV machine to validate it. Upon starting my server I received the following error:`

我将 Log4J2 添加到我的应用程序中。我将所有 Log4J2 .jar 文件复制到 LIB 目录并创建了 Log4J2.xml 文件来支持它。我的代码已更新以导入必要的 Log Manager 和 Logger API。然后我添加了静态最终记录器方法并在我的代码中调用了记录器 API。Eclipse 中的所有编译文件。我继续在我的 DEV 机器上启动我的服务器以验证它。启动服务器后,我收到以下错误:`

2014-10-19 21:39:31.753:INFO:oejs.Server:jetty-8.1.14.v20131031
2014-10-19 21:39:32.680:WARN:oejuc.AbstractLifeCycle:FAILED FoundationStartup: java.lang.NoClassDefFoundError: org/slf4j/Logger
java.lang.NoClassDefFoundError: org/slf4j/Logger
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:474)
    at com.global.service.FoundationStartup.<clinit>(FoundationStartup.java:19)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:957)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:514)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1221)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:282)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.wst.server.preview.internal.PreviewStarter.run(PreviewStarter.java:72)
    at org.eclipse.wst.server.preview.internal.PreviewStarter.main(PreviewStarter.java:29)
Caused by: 
java.lang.ClassNotFoundException: org.slf4j.Logger
    at java.net.URLClassLoader.run(Unknown Source)
    at java.net.URLClassLoader.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:424)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:377)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:474)
    at com.global.service.FoundationStartup.<clinit>(FoundationStartup.java:19)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at org.eclipse.jetty.servlet.ServletContextHandler$Context.createServlet(ServletContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHolder.newInstance(ServletHolder.java:957)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:514)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1221)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:229)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:282)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.wst.server.preview.internal.PreviewStarter.run(PreviewStarter.java:72)
    at org.eclipse.wst.server.preview.internal.PreviewStarter.main(PreviewStarter.java:29)`

What is wrong with my configuration? Do I need to download another .JAR or is this a configuration problem?

我的配置有什么问题?我需要下载另一个 .JAR 还是这是一个配置问题?

Thanks, Stephen.

谢谢,斯蒂芬。

I copied the slf4j .jars to my lib and reran the server. The following errors appeared. Any ideas why these errors are being thrown now?

我将 slf4j .jars 复制到我的库并重新运行服务器。出现以下错误。为什么现在抛出这些错误的任何想法?

.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)
    at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:51)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:277)
    at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:41)

采纳答案by Remko Popma

The answer is hidden in the manualpage:

答案隐藏在手册页中:

Use of the Log4j 2 SLF4J Binding (log4j-slf4j-impl-2.0.jar) together with the SLF4J adapter (log4j-to-slf4j-2.0.jar) should never be attempted, as it will cause events to endlessly be routed between SLF4J and Log4j 2.

永远不要尝试使用 Log4j 2 SLF4J 绑定(log4j-slf4j-impl-2.0.jar)和 SLF4J 适配器(log4j-to-slf4j-2.0.jar),因为它会导致事件在 SLF4J 之间无休止地路由和 Log4j 2。

You want to keepthe log4j-slf4j-impl-2.xx.jar and removethe log4j-to-slf4j-2.xx.jar.

您想保留log4j-slf4j-impl-2.xx.jar 并删除log4j-to-slf4j-2.xx.jar。

回答by triggerNZ

Yes. you need the SLF4J jar file. You can download it at: http://www.slf4j.org/download.html

是的。您需要 SLF4J jar 文件。您可以在以下网址下载:http: //www.slf4j.org/download.html

回答by Ankur Singhal

A NoClassDefFoundErrorwith ClassNotFoundExceptionspecifies that the particular class is missing during runtime.

一个NoClassDefFoundErrorClassNotFoundException该特定类是运行过程中缺少指定。

You have to provide one of the various SLF4Jimplementation .jar files in the classpath

您必须SLF4J在类路径中提供各种实现 .jar 文件之一