The mistake java.lang.NoClassDefFoundError
is one of the exceptions core of Java, which occurs at runtime when a class existing could not be loaded due to the lack of another class it depends on or, for example, when a static boot block has released an exception.
That is to say, that mistake nay occurs for lack of class org.slf4j.LoggerFactory
, but for lack of some other class she needs.
The log library called Simple Logging Facade for Java (SLF4J) is only a standardized interface for accessing logs, but you still need to include an implementation of logs such as Log4j or Logback, etc..
How you solve it depends on how you use your program:
- If it is a simple program running per command line, add the required 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 folder
WEB-INF/lib
.
Which jars should be included in the classpath depends on which library is used in conjunction with SLF4J and what 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
.
Excellent answer, even for me who did not know how the full meaning of the java.lang error.Noclassdeffounderror
– adelmo00