java.lang.ClassNotFoundException:org.apache.log4j.Level

时间:2012-05-14 14:48:30

标签: java hibernate exception log4j slf4j

我正在尝试在swing应用程序中使用hibernate 3.5.1 final 这是我正在使用的罐子:

  • 冬眠核-3.5.1-最终
  • 冬眠-的EntityManager-3.5.1-最终
  • hibernate-jpa-2.0-api-1.0.0.Final
  • 冬眠的注解-3.5.1-最终
  • hibernate-commons-annotations-3.2.0.Final
  • DOM4J-1.6.1
  • SLF4J-API-1.6.4
  • SLF4J-log4j12-1.6.4

当我尝试运行该应用程序时,出现以下错误:

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)

3 个答案:

答案 0 :(得分:36)

您还需要在类路径中包含Log4J JAR文件。

请注意,slf4j-log4j12-1.6.4.jar只是一个适配器,可以通过SLF4J API使用Log4J。它不包含Log4J的实际实现。

答案 1 :(得分:5)

您需要下载log4j并添加类路径。

答案 2 :(得分:0)

在我的环境中,我只是将两个文件添加到类路径中。工作正常。

slf4j-jdk14-1.7.25.jar
slf4j-api-1.7.25.jar