0

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

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:

# 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$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
user2892662
  • 23
  • 1
  • 2
  • 5
  • It looks like this is a tomcat web application? Where specifically are each of the slf4j jars deployed? And could you edit your question to include the complete stacktrace for this exception that you're getting? – Kenster Apr 02 '15 at 20:52
  • its a simple java program and I am just using this as a logger. It was working when I built it with eclipse. And I have added the exception. – user2892662 Apr 02 '15 at 21:05
  • also, my log4j.properties file is located in the src directory. – user2892662 Apr 02 '15 at 21:41
  • I saw the catalina reference in your log4j.properties and thought it might be http://stackoverflow.com/q/24342963/13317. But it looks like slf4j-api is just missing from your class path. – Kenster Apr 02 '15 at 21:47

2 Answers2

0

Probably slf4j.jar is not getting loaded for some reason.You can include some jars to class path:

  • slf4j-log4j12
  • slf4j-simple .. After all clean your project and run.It will run successfully.
tuğrul altun
  • 131
  • 1
  • 4
  • When I add those two, clean and build, i get this: `SLF4J: Class path contains multiple SLF4J bindings.` SLF4J: Found binding in [jar:file:/C://workspace/External_Jar_Files/slf4j-1.7.11/slf4j-log4j12-1.7.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/workspace/External_Jar_Files/slf4j-1.7.11/slf4j-simple-1.7.11.jar!/org/slf4j/impl/StaticLoggerBinder.class] – user2892662 Apr 02 '15 at 20:56
  • Try to remove the `slf4j-log4j12-1.7.11.jar` from your classpath. – Dinei Oct 08 '15 at 00:57
0

In case, your getting "java.lang.NoClassDefFoundError: Lorg/slf4j/Logger", while starting the Tomcat server,

  1. Then either you have not copied the shared tomcat properly or
  2. There is a issue with "apache tomcat/conf/catalina.properties" file.

Solution

  1. Download new Apache tomcat server and use it.
  2. Delete the existing server, copy the server from downloads and paste it again to the same location and use it.
bummi
  • 27,123
  • 14
  • 62
  • 101
RNaidu
  • 1
  • 2