The java.lang.NoClassDefFoundError
error is one of the core exceptions of Java, which occurs at runtime when an existing class could not be loaded because of missing another class on which it depends or, for example, when a static boot block has thrown an exception.
That is, this error does not occur for lack of class org.slf4j.LoggerFactory
, but for lack of any other class it needs .
The logging library called Simple Logging Facade for Java (SLF4J) is just a standardized interface for accessing logs, but you still need to include an implementation of logs such as Log4j or Logback , etc.
How you resolve depends on how you use your program:
- If it is a simple program running by command line, add the necessary dependencies by specifying to the Java classpath with the parameter
-cp
.
- If it is a web application you can use application server logs or include your log library in the
WEB-INF/lib
folder.
Which jars should be included in the classpath depends on which library is used in conjunction with SLF4J and which features the application uses:
- For simple logs using only SLF4J, you can include:
-
slf4j-api-1.x.xx.jar
-
slf4j-simple-1.x.xx.jar
- To use Log4j:
-
slf4j-api-1.x.xx.jar
-
log4j.jar
-
slf4j-log4j12-1.x.xx.jar
, the integration jar between the two libraries
- To use Logback:
-
slf4j-api-1.x.xx.jar
-
logback-classic-1.0.13.jar
-
logback-core-1.0.13.jar
.