gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError : org/slf4j/ILoggerFactory 中的异常

转载 作者:行者123 更新时间:2023-12-02 05:50:29 28 4
gpt4 key购买 nike

我正在尝试在 Eclipse 项目中使用 log4j.2.x 进行日志记录。我命名为 log4j2.xml 的 conf 文件直接在 java 项目下,我在类路径中有必要的 jars。测试时,我看到以下错误消息。谁能告诉我这个问题的解决方案?
log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?> <configuration status="WARN">  <appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console> </appenders> <loggers>
<root level="error">
<appender-ref ref="Console"/>
</root> </loggers></configuration>

控制台中的错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/ILoggerFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.apache.logging.slf4j.SLF4JLoggerContextFactory.<init>(SLF4JLoggerContextFactory.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:84)
at Browserbot.<clinit>(Browserbot.java:17)Caused by: java.lang.ClassNotFoundException: org.slf4j.ILoggerFactory
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:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 23 more

我的 Java 文件:
public class Browserbot {
static Logger logger = LogManager.getLogger(Browserbot.class.getName());

public static void main(String[] args){

logger.error("File Not Found");}}

最佳答案

您失踪了 slf4j.jar运行程序时在您的类路径中。要了解 slf4j 和 log4j 之间的依赖关系、下载 jar 等,请访问以下链接:

http://www.slf4j.org

关于java - 线程 "main"java.lang.NoClassDefFoundError : org/slf4j/ILoggerFactory 中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18421091/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com