我将项目从eclipse移到了netbeans,当我在构建它之后尝试运行.jar文件时,我现在收到Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
错误。该程序运行正常
以下是我在类路径中的内容:
slf4j-api-1.7.11.jar
slf4j-ext-1.7.11.jar
log4j-1.2.17.jar
这是我的记录器:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Log {
public static final Logger logger = LoggerFactory.getLogger(Log.class);
public Log(){
}
}
log4j.properties:
# Root logger option
log4j.rootLogger=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#Redirect to Tomcat logs folder
#log4j.appender.file.File=${catalina.home}/logs/logging.log
log4j.appender.file.File=C:\\Log.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
当我想记录某些内容时我会调用什么(这就是它炸弹并抛出错误的地方):
Log.logger.info("");
例外:
Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.xxx.xxxx.Log.<clinit>(Log.java:8)
at com.xxx.xxxx.MainGui.PrintHeaderForLog(MainGui.java:319)
at com.xxx.xxxx.MainGui.<init>(MainGui.java:69)
at com.xxx.xxxx.MainGui.<clinit>(MainGui.java:48)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.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)
... 4 more
答案 0 :(得分:0)
可能slf4j.jar由于某种原因没有加载。你可以在类路径中加入一些jar:
答案 1 :(得分:0)
如果您在启动Tomcat服务器时获得“java.lang.NoClassDefFoundError:Lorg / slf4j / Logger”,
解决方案