java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 使用 NetBeans 构建 .jar 后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29421615/
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
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory after building .jar with NetBeans
提问by user2892662
I moved my project over from eclipse to netbeans and I am now receiving Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
error when I try to run the .jar file after building it. The program runs fine from
我将我的项目从 eclipse 移到了 netbeans,Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
当我在构建后尝试运行 .jar 文件时,我现在收到错误。该程序运行良好
Here is what I have in my classpath:
这是我的类路径中的内容:
slf4j-api-1.7.11.jar
slf4j-ext-1.7.11.jar
log4j-1.2.17.jar
Here is my logger:
这是我的记录器:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Log {
public static final Logger logger = LoggerFactory.getLogger(Log.class);
public Log(){
}
}
log4j.properties:
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
What I call when I want to log something (and this is where it bombs out and throws that error):
当我想记录一些东西时我叫什么(这是它爆炸并抛出那个错误的地方):
Log.logger.info("");
Exception:
例外:
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.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)
... 4 more
回答by tu?rul altun
Probably slf4j.jar is not getting loaded for some reason.You can include some jars to class path:
slf4j.jar 可能由于某种原因没有被加载。你可以在类路径中包含一些 jars:
- slf4j-log4j12
- slf4j-simple .. After all clean your project and run.It will run successfully.
- slf4j-log4j12
- slf4j-simple .. 毕竟清理你的项目并运行。它会成功运行。
回答by RNaidu
In case, your getting "java.lang.NoClassDefFoundError: Lorg/slf4j/Logger", while starting the Tomcat server,
如果您在启动 Tomcat 服务器时收到“java.lang.NoClassDefFoundError: Lorg/slf4j/Logger”,
- Then either you have not copied the shared tomcat properly or
- There is a issue with "apache tomcat/conf/catalina.properties" file.
- 那么要么你没有正确复制共享的 tomcat 要么
- “apache tomcat/conf/catalina.properties”文件存在问题。
Solution
解决方案
- Download new Apache tomcat server and use it.
- Delete the existing server, copy the server from downloads and paste it again to the same location and use it.
- 下载新的 Apache tomcat 服务器并使用它。
- 删除现有服务器,从下载中复制服务器并将其再次粘贴到同一位置并使用它。