How To Ready Exception Inwards Thread Principal Java.Lang.Noclassdeffounderror: Org/Slf4j/Loggerfactory Inwards Java
Wednesday, May 30, 2018
Add Comment
This mistake agency your code or whatever external library yous are using inwards your application is using the SLF4J library, an opened upwardly root 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 inwards thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory. If yous await at the error, yous volition encounter that it's maxim it is non able to notice the flat org/slf4j/LoggerFactory or org.slf4j.LoggerFactory. The bundle cite indicates that it's business office of SLF4j, thence yous require SLF4j JAR files e.g. slf4j-api-1.7.2.jar inwards your application's classpath. So, teach ahead too download the JAR file from SLFj website or from Maven Central repository too 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 upwardly similar that inwards a complex surround due to meliorate design.
By using SLF4j, yous tin switch to whatever logging library without changing a unmarried business of code inwards your application e.g. yous switch to Log4j from java.util.logging or LogBack.
Hence, apart from SLF4j binaries, yous also require proper logging binaries e.g. log4j-1.2.16.jar or logback-1.2.3.jar if yous are using LogBack library. Those are the libraries which volition live on called yesteryear SLF4j for doing actual work.
Sometime, yous teach this mistake when your code is non genuinely using SLF4j but yous are using a tool or library, which internally using it.
For example, I was using log4jdbc.jar, a tool to log SQL statements too their timing spell running JDBC code too it laissez passer on me this error:
Exception inwards 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)
... vi more
Since my computer program was elementary too I wasn't genuinely using whatever Logging API, I was surprised from where does this mistake came in, but, a quick await to the stack line suggested that its the net.sf.log4jdbc.DriverSpy flat which is using SLF4j for logging.
Later when I read the documentation of log4jdbc, I realize nosotros require both SLF4J too Log4J JAR files to teach it working. Since I was running my attempt computer program inwards Eclipse, it was slow for me, I just dropped the slf4j-api-1.7.2.jar too log4j-1.2.16.jar inwards my projection directory. Since it's included inwards classpath it got picked upwardly 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 endeavour to comprehend roughly scenarios to solve this error.
1. If yous are running your Java computer program using a batch script or vanquish script, await for -cp or -classpath selection too encounter where it is picking the JAR files. You tin set slf4j-api-1.7.2.jar too log4j-1.2.16.jar on those directories.
If yous computer program is running on Linux server, yous tin but just produce ps -ef | grep java too encounter the JVM arguments of your Java computer program to notice which directories are inwards the classpath. If yous convey access to the script yous tin 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 surround variable so yous require to just echo $CLASSPATH too set the slf4j-API-1.7.2.jar too log4j-1.2.16.jar files into the directory already introduce inwards the CLASSPATH or yous tin just add together a novel directory into the CLASSPATH. See this article to know how to brand a alter inwards CLASSPATH surround variable.
3. If yous are using Eclipse so just drib the slf4j-API-1.7.2.jar too log4j-1.2.16.jar into your projection directory. It is yesteryear default inwards the classpath so the JARs volition live on picked upwardly yesteryear your application.
If yous are using Maven for edifice your projection too managing dependencies, yous tin also add together next Maven dependency to download SLF4J too 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 yous add together these dependencies, brand certain yous produce a create clean create from Maven to genuinely download these dependencies from Maven's remote repository.
That's all most how to create Exception inwards thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory mistake inwards Java. All yous require to produce is add together the slf4j-API-1.7.2.jar too log4j-1.2.16.jar files into your classpath.
The version may differ depending upon private cases but yous must add together a compatible version of SLF4J too the logging library yous are using. For example, if your application is using LogBack yous require to add together a relevant version of the logback.jar file.
If yous role Maven, yous tin also download these JAR files yesteryear adding relevant dependencies inwards pom.xml otherwise, yous tin just download the JAR file from Maven key or straight from SLF4j too Log4j website too add together to your application's classpath.
If yous notice whatever problem adding SLF4J too LOG4j JAR files into classpath yous tin also say us inwards the comment department too nosotros tin endeavour to deal yous out.
Other Java troubleshooting Guides yous may like
How to solve ArrayIndexOutOfBoundsException inwards Java? (guide)
How to solve NullPointerException inwards 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 ascendance line? (solution)
How to solve "No JVM found, Please install 64-bit JDK" mistake inwards Android Studio? (solution)
How to bargain amongst SQLException "No Suitable driver flora " mistake inwards JDBC too MySQL? (guide)
How to solve NumberFormatException inwards Java? (guide)
How to solve Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied? (solution)
How to create java.lang.ArrayIndexOutOfBoundsException: i inwards Java? (solution)
How to create java.net.SocketException: Software caused connectedness abort: recv failed (fix)
Thanks for reading this tutorial, if yous similar this tutorial so delight part amongst your friends too colleagues. If yous convey whatever query or proposition so delight drib a comment.
Sumber https://javarevisited.blogspot.com/
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 upwardly similar that inwards a complex surround due to meliorate design.
By using SLF4j, yous tin switch to whatever logging library without changing a unmarried business of code inwards your application e.g. yous switch to Log4j from java.util.logging or LogBack.
Hence, apart from SLF4j binaries, yous also require proper logging binaries e.g. log4j-1.2.16.jar or logback-1.2.3.jar if yous are using LogBack library. Those are the libraries which volition live on called yesteryear SLF4j for doing actual work.
Sometime, yous teach this mistake when your code is non genuinely using SLF4j but yous are using a tool or library, which internally using it.
For example, I was using log4jdbc.jar, a tool to log SQL statements too their timing spell running JDBC code too it laissez passer on me this error:
Exception inwards 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)
... vi more
Since my computer program was elementary too I wasn't genuinely using whatever Logging API, I was surprised from where does this mistake came in, but, a quick await to the stack line suggested that its the net.sf.log4jdbc.DriverSpy flat which is using SLF4j for logging.
Later when I read the documentation of log4jdbc, I realize nosotros require both SLF4J too Log4J JAR files to teach it working. Since I was running my attempt computer program inwards Eclipse, it was slow for me, I just dropped the slf4j-api-1.7.2.jar too log4j-1.2.16.jar inwards my projection directory. Since it's included inwards classpath it got picked upwardly 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 endeavour to comprehend roughly scenarios to solve this error.
1. If yous are running your Java computer program using a batch script or vanquish script, await for -cp or -classpath selection too encounter where it is picking the JAR files. You tin set slf4j-api-1.7.2.jar too log4j-1.2.16.jar on those directories.
If yous computer program is running on Linux server, yous tin but just produce ps -ef | grep java too encounter the JVM arguments of your Java computer program to notice which directories are inwards the classpath. If yous convey access to the script yous tin 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 surround variable so yous require to just echo $CLASSPATH too set the slf4j-API-1.7.2.jar too log4j-1.2.16.jar files into the directory already introduce inwards the CLASSPATH or yous tin just add together a novel directory into the CLASSPATH. See this article to know how to brand a alter inwards CLASSPATH surround variable.
3. If yous are using Eclipse so just drib the slf4j-API-1.7.2.jar too log4j-1.2.16.jar into your projection directory. It is yesteryear default inwards the classpath so the JARs volition live on picked upwardly yesteryear your application.
How to download SLF4j too Log4j JAR file
You tin either download slf4j-api-1.7.2.jar too 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 yous are using Maven for edifice your projection too managing dependencies, yous tin also add together next Maven dependency to download SLF4J too 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 yous add together these dependencies, brand certain yous produce a create clean create from Maven to genuinely download these dependencies from Maven's remote repository.
That's all most how to create Exception inwards thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory mistake inwards Java. All yous require to produce is add together the slf4j-API-1.7.2.jar too log4j-1.2.16.jar files into your classpath.
The version may differ depending upon private cases but yous must add together a compatible version of SLF4J too the logging library yous are using. For example, if your application is using LogBack yous require to add together a relevant version of the logback.jar file.
If yous role Maven, yous tin also download these JAR files yesteryear adding relevant dependencies inwards pom.xml otherwise, yous tin just download the JAR file from Maven key or straight from SLF4j too Log4j website too add together to your application's classpath.
If yous notice whatever problem adding SLF4J too LOG4j JAR files into classpath yous tin also say us inwards the comment department too nosotros tin endeavour to deal yous out.
Other Java troubleshooting Guides yous may like
How to solve ArrayIndexOutOfBoundsException inwards Java? (guide)
How to solve NullPointerException inwards 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 ascendance line? (solution)
How to solve "No JVM found, Please install 64-bit JDK" mistake inwards Android Studio? (solution)
How to bargain amongst SQLException "No Suitable driver flora " mistake inwards JDBC too MySQL? (guide)
How to solve NumberFormatException inwards Java? (guide)
How to solve Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied? (solution)
How to create java.lang.ArrayIndexOutOfBoundsException: i inwards Java? (solution)
How to create java.net.SocketException: Software caused connectedness abort: recv failed (fix)
Thanks for reading this tutorial, if yous similar this tutorial so delight part amongst your friends too colleagues. If yous convey whatever query or proposition so delight drib a comment.
0 Response to "How To Ready Exception Inwards Thread Principal Java.Lang.Noclassdeffounderror: Org/Slf4j/Loggerfactory Inwards Java"
Post a Comment