How to fix exception: Failed to instantiate SLF4J LoggerFactory?
Asked Answered
S

5

8

I am trying to write a java web crawler for semantic web using jena library. I have build project using Netbeans. I am receiving two errors:

  1. Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: org/apache/log4j/Level

  2. Could not initialize class com.hp.hpl.jena.rdf.model.impl.ModelCom at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)

I have included slf4j-api and slf4j-log both libraries.

Sputnik answered 6/3, 2013 at 11:28 Comment(0)
Z
11

You should also include log4j library as slf4j-log4j is just a static binder.

Zampino answered 6/3, 2013 at 11:36 Comment(0)
B
7

You should include slf4j-api-x.x.x.jar and slf4j-simple-x.x.x.jar in your classpath.

Brinson answered 22/1, 2014 at 0:19 Comment(0)
S
2

I tried all permutation and combination but finally slf4j-api- and slf4j-simple- worked well.

Sachsen answered 15/12, 2015 at 20:30 Comment(0)
M
0

As error suggested:

Failed to instantiate SLF4J LoggerFactory

you need to place your corresponding slf4j-*-*.jar binding files into your classpath folder.

You can locate them by locate slf4j if present.

As of SLF4J version 1.6.0, if no binding is found on the class path, then slf4j-api will default to a no-operation implementation discarding all log requests.

Tomcat

If using Tomcat, these files you can copy either into /usr/share/tomcat7/lib or your webapp folder /var/lib/tomcat7/webapps/*/WEB-INF/lib.

Solr

If you're using Solr or you want use the files from there (which are included by default), you can find them in dist/solrj-lib and example/lib/ext.


See: The Simple Logging Facade for Java (SLF4J) user manual

Merchandise answered 9/4, 2015 at 21:24 Comment(0)
M
0

In my case the Failed to instantiate SLF4J LoggerFactory happened when I added a module-info.java to my project. The solution was to add these two lines to my module-info.java file:

requires org.apache.logging.log4j;
requires org.apache.logging.log4j.core;

In case it helps someone who reaches this question the way I did.

Maxama answered 13/8, 2024 at 11:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.