java.lang.ClassNotFoundException: org.apache.log4j.Level
Asked Answered
W

3

24

I'm trying to use hibernate 3.5.1 final in a swing application and here are the jars I'm using:

  • hibernate-core-3.5.1-Final
  • hibernate-entitymanager-3.5.1-Final
  • hibernate-jpa-2.0-api-1.0.0.Final
  • hibernate-annotations-3.5.1-Final
  • hibernate-commons-annotations-3.2.0.Final
  • dom4j-1.6.1
  • slf4j-api-1.6.4
  • slf4j-log4j12-1.6.4

When I try to run the application, I get the following error:

Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:165)
    at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:127)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at com.xeno.xecamp.desktopManagement.Main.main(Main.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 11 more
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:165)
    at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:127)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at com.xeno.xecamp.desktopManagement.Main.main(Main.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Waadt answered 14/5, 2012 at 14:48 Comment(1)
If you're trying to use symbolic links to attach your jar files, then see #22241276Joejoeann
T
40

You also need to include the Log4J JAR file in the classpath.

Note that slf4j-log4j12-1.6.4.jar is only an adapter to make it possible to use Log4J via the SLF4J API. It does not contain the actual implementation of Log4J.

Treponema answered 14/5, 2012 at 14:52 Comment(4)
can you please tell me the maven dependency compatible with the version i am using ?Waadt
well i just needed log4j-1.2.16.jarWaadt
adding log4j-1.2.16.jar also solved the problem in my case but slf4j-log4j12-1.6.4.jar didn'tTranseunt
actually adding maven dependency as such was not sufficient in my case, i also had to add the flag: <scope>build</scope> to make it run: <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <scope>build</scope> </dependency>Hamate
S
5

You need to download log4j and add in your classpath.

Sylvan answered 14/5, 2012 at 14:52 Comment(0)
S
2

In my environment, I just added the two files to class path. And is work fine.

slf4j-jdk14-1.7.25.jar
slf4j-api-1.7.25.jar
Sse answered 21/5, 2018 at 3:36 Comment(2)
Thanks, this worked for me in October 2019. I didn't even need the log jar, the slf4j-jdk took care of it.Devy
This worked for me today oct 20th 2023. Except that my two files are of higher versions.Pinko

© 2022 - 2024 — McMap. All rights reserved.