How To Cook Exception Inwards Thread Primary Java.Lang.Noclassdeffounderror: Org/Slf4j/Loggerfactory Inwards Java
This mistake agency your code or whatever external library you lot are using inward your application is using the SLF4J library, an opened upwards origin logging library, but it is non able to notice the required JAR file e.g. slf4j-api-1.7.2.jar hence it's throwing Exception inward thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory. If you lot hold off at the error, you lot volition come across that it's proverb it is non able to notice the degree org/slf4j/LoggerFactory or org.slf4j.LoggerFactory. The bundle refer indicates that it's business office of SLF4j, so you lot involve SLF4j JAR files e.g. slf4j-api-1.7.2.jar inward your application's classpath. So, become ahead in addition to download the JAR file from SLFj website or from Maven Central repository in addition to restart your application.
Btw, the SLF4j is non genuinely a logging API but it provides abstraction over other logging libraries e.g. Log4j, java.util.logging, or LogBak. It's similar to the commons-logging library but it doesn't mess upwards similar that inward a complex environs due to ameliorate design.
By using SLF4j, you lot tin laissez passer on notice switch to whatever logging library without changing a unmarried job of code inward your application e.g. you lot switch to Log4j from java.util.logging or LogBack.
Hence, apart from SLF4j binaries, you lot also involve proper logging binaries e.g. log4j-1.2.16.jar or logback-1.2.3.jar if you lot are using LogBack library. Those are the libraries which volition endure called yesteryear SLF4j for doing actual work.
Sometime, you lot instruct this mistake when your code is non genuinely using SLF4j but you lot are using a tool or library, which internally using it.
For example, I was using log4jdbc.jar, a tool to log SQL statements in addition to their timing spell running JDBC code in addition to it laissez passer on me this error:
Exception inward thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at net.sf.log4jdbc.Slf4jSpyLogDelegator.<init>(Slf4jSpyLogDelegator.java:45)
at net.sf.log4jdbc.SpyLogFactory.<clinit>(SpyLogFactory.java:37)
at net.sf.log4jdbc.DriverSpy.<clinit>(DriverSpy.java:106)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at Testing.main(Testing.java:15)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... half-dozen more
Since my computer program was uncomplicated in addition to I wasn't genuinely using whatever Logging API, I was surprised from where does this mistake came in, but, a quick hold off to the stack draw suggested that its the net.sf.log4jdbc.DriverSpy degree which is using SLF4j for logging.
Later when I read the documentation of log4jdbc, I realize nosotros involve both SLF4J in addition to Log4J JAR files to instruct it working. Since I was running my evidence computer program inward Eclipse, it was slow for me, I just dropped the slf4j-api-1.7.2.jar in addition to log4j-1.2.16.jar inward my projection directory. Since it's included inward classpath it got picked upwards easily.
Btw, classpath problems are non slow to solve for many Java programmers because they don't know where just to set this JAR file to solve their problem. Since every application setup is different, I'll endeavor to comprehend to a greater extent than or less scenarios to solve this error.
1. If you lot are running your Java computer program using a batch script or musical rhythm script, hold off for -cp or -classpath selection in addition to come across where it is picking the JAR files. You tin laissez passer on notice set slf4j-api-1.7.2.jar in addition to log4j-1.2.16.jar on those directories.
If you lot computer program is running on Linux server, you lot tin laissez passer on notice but just create ps -ef | grep java in addition to come across the JVM arguments of your Java computer program to notice which directories are inward the classpath. If you lot convey access to the script you lot tin laissez passer on notice also add together a novel directory to the classpath.
$ ps -ef | grep java
/opt/jre/v1.7.0_80-64bit/bin/java -Xmx8192M -Xms8192M -classpath /app/myapp.jar:/app/jackson.jar MyApplication
2. If your computer program is using CLASSPATH environs variable in addition to so you lot involve to just echo $CLASSPATH in addition to set the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar files into the directory already acquaint inward the CLASSPATH or you lot tin laissez passer on notice just add together a novel directory into the CLASSPATH. See this article to know how to brand a alter inward CLASSPATH environs variable.
3. If you lot are using Eclipse in addition to so just drib the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar into your projection directory. It is yesteryear default inward the classpath so the JARs volition endure picked upwards yesteryear your application.
If you lot are using Maven for edifice your projection in addition to managing dependencies, you lot tin laissez passer on notice also add together next Maven dependency to download SLF4J in addition to Log4j JAR files into your project:
<!-- SLF4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<!-- LOG4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.2.16</version>
</dependency>
Once you lot add together these dependencies, brand certain you lot create a create clean create from Maven to genuinely download these dependencies from Maven's remote repository.
That's all almost how to create Exception inward thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory mistake inward Java. All you lot involve to create is add together the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar files into your classpath.
The version may differ depending upon private cases but you lot must add together a compatible version of SLF4J in addition to the logging library you lot are using. For example, if your application is using LogBack you lot involve to add together a relevant version of the logback.jar file.
If you lot purpose Maven, you lot tin laissez passer on notice also download these JAR files yesteryear adding relevant dependencies inward pom.xml otherwise, you lot tin laissez passer on notice just download the JAR file from Maven primal or remove from SLF4j in addition to Log4j website in addition to add together to your application's classpath.
If you lot notice whatever problem adding SLF4J in addition to LOG4j JAR files into classpath you lot tin laissez passer on notice also order us inward the comment department in addition to nosotros tin laissez passer on notice endeavor to assistance you lot out.
Other Java troubleshooting Guides you lot may like
How to solve ArrayIndexOutOfBoundsException inward Java? (guide)
How to solve NullPointerException inward Java? (guide)
How to solve the "System cannot notice the Path specified" error? (solution)
How to solve NoClassDefFoundError spell running Java computer program from a ascendency line? (solution)
How to solve "No JVM found, Please install 64-bit JDK" mistake inward Android Studio? (solution)
How to bargain alongside SQLException "No Suitable driver flora " mistake inward JDBC in addition to MySQL? (guide)
How to solve NumberFormatException inward Java? (guide)
How to solve Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied? (solution)
How to create java.lang.ArrayIndexOutOfBoundsException: i inward Java? (solution)
How to create java.net.SocketException: Software caused connectedness abort: recv failed (fix)
Thanks for reading this tutorial, if you lot similar this tutorial in addition to so delight portion alongside your friends in addition to colleagues. If you lot convey whatever interrogation or proposition in addition to so delight drib a comment.
Btw, the SLF4j is non genuinely a logging API but it provides abstraction over other logging libraries e.g. Log4j, java.util.logging, or LogBak. It's similar to the commons-logging library but it doesn't mess upwards similar that inward a complex environs due to ameliorate design.
By using SLF4j, you lot tin laissez passer on notice switch to whatever logging library without changing a unmarried job of code inward your application e.g. you lot switch to Log4j from java.util.logging or LogBack.
Hence, apart from SLF4j binaries, you lot also involve proper logging binaries e.g. log4j-1.2.16.jar or logback-1.2.3.jar if you lot are using LogBack library. Those are the libraries which volition endure called yesteryear SLF4j for doing actual work.
Sometime, you lot instruct this mistake when your code is non genuinely using SLF4j but you lot are using a tool or library, which internally using it.
For example, I was using log4jdbc.jar, a tool to log SQL statements in addition to their timing spell running JDBC code in addition to it laissez passer on me this error:
Exception inward thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at net.sf.log4jdbc.Slf4jSpyLogDelegator.<init>(Slf4jSpyLogDelegator.java:45)
at net.sf.log4jdbc.SpyLogFactory.<clinit>(SpyLogFactory.java:37)
at net.sf.log4jdbc.DriverSpy.<clinit>(DriverSpy.java:106)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at Testing.main(Testing.java:15)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... half-dozen more
Since my computer program was uncomplicated in addition to I wasn't genuinely using whatever Logging API, I was surprised from where does this mistake came in, but, a quick hold off to the stack draw suggested that its the net.sf.log4jdbc.DriverSpy degree which is using SLF4j for logging.
Later when I read the documentation of log4jdbc, I realize nosotros involve both SLF4J in addition to Log4J JAR files to instruct it working. Since I was running my evidence computer program inward Eclipse, it was slow for me, I just dropped the slf4j-api-1.7.2.jar in addition to log4j-1.2.16.jar inward my projection directory. Since it's included inward classpath it got picked upwards easily.
Btw, classpath problems are non slow to solve for many Java programmers because they don't know where just to set this JAR file to solve their problem. Since every application setup is different, I'll endeavor to comprehend to a greater extent than or less scenarios to solve this error.
1. If you lot are running your Java computer program using a batch script or musical rhythm script, hold off for -cp or -classpath selection in addition to come across where it is picking the JAR files. You tin laissez passer on notice set slf4j-api-1.7.2.jar in addition to log4j-1.2.16.jar on those directories.
If you lot computer program is running on Linux server, you lot tin laissez passer on notice but just create ps -ef | grep java in addition to come across the JVM arguments of your Java computer program to notice which directories are inward the classpath. If you lot convey access to the script you lot tin laissez passer on notice also add together a novel directory to the classpath.
$ ps -ef | grep java
/opt/jre/v1.7.0_80-64bit/bin/java -Xmx8192M -Xms8192M -classpath /app/myapp.jar:/app/jackson.jar MyApplication
2. If your computer program is using CLASSPATH environs variable in addition to so you lot involve to just echo $CLASSPATH in addition to set the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar files into the directory already acquaint inward the CLASSPATH or you lot tin laissez passer on notice just add together a novel directory into the CLASSPATH. See this article to know how to brand a alter inward CLASSPATH environs variable.
3. If you lot are using Eclipse in addition to so just drib the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar into your projection directory. It is yesteryear default inward the classpath so the JARs volition endure picked upwards yesteryear your application.
How to download SLF4j in addition to Log4j JAR file
You tin laissez passer on notice either download slf4j-api-1.7.2.jar in addition to log4j-1.2.16.jar from respective websites e.g. https://www.slf4j.org and https://logging.apache.org/log4j/1.2/download.html or just download them from the Maven Central repository.If you lot are using Maven for edifice your projection in addition to managing dependencies, you lot tin laissez passer on notice also add together next Maven dependency to download SLF4J in addition to Log4j JAR files into your project:
<!-- SLF4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<!-- LOG4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.2.16</version>
</dependency>
Once you lot add together these dependencies, brand certain you lot create a create clean create from Maven to genuinely download these dependencies from Maven's remote repository.
That's all almost how to create Exception inward thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory mistake inward Java. All you lot involve to create is add together the slf4j-API-1.7.2.jar in addition to log4j-1.2.16.jar files into your classpath.
The version may differ depending upon private cases but you lot must add together a compatible version of SLF4J in addition to the logging library you lot are using. For example, if your application is using LogBack you lot involve to add together a relevant version of the logback.jar file.
If you lot purpose Maven, you lot tin laissez passer on notice also download these JAR files yesteryear adding relevant dependencies inward pom.xml otherwise, you lot tin laissez passer on notice just download the JAR file from Maven primal or remove from SLF4j in addition to Log4j website in addition to add together to your application's classpath.
If you lot notice whatever problem adding SLF4J in addition to LOG4j JAR files into classpath you lot tin laissez passer on notice also order us inward the comment department in addition to nosotros tin laissez passer on notice endeavor to assistance you lot out.
Other Java troubleshooting Guides you lot may like
How to solve ArrayIndexOutOfBoundsException inward Java? (guide)
How to solve NullPointerException inward Java? (guide)
How to solve the "System cannot notice the Path specified" error? (solution)
How to solve NoClassDefFoundError spell running Java computer program from a ascendency line? (solution)
How to solve "No JVM found, Please install 64-bit JDK" mistake inward Android Studio? (solution)
How to bargain alongside SQLException "No Suitable driver flora " mistake inward JDBC in addition to MySQL? (guide)
How to solve NumberFormatException inward Java? (guide)
How to solve Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied? (solution)
How to create java.lang.ArrayIndexOutOfBoundsException: i inward Java? (solution)
How to create java.net.SocketException: Software caused connectedness abort: recv failed (fix)
Thanks for reading this tutorial, if you lot similar this tutorial in addition to so delight portion alongside your friends in addition to colleagues. If you lot convey whatever interrogation or proposition in addition to so delight drib a comment.
Belum ada Komentar untuk "How To Cook Exception Inwards Thread Primary Java.Lang.Noclassdeffounderror: Org/Slf4j/Loggerfactory Inwards Java"
Posting Komentar