本文介绍了java.lang.ClassNotFoundException:org.apache.log4j.Level的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在swing应用程序
中使用hibernate 3.5.1 final,这里是我使用的jar:

I'm trying to use hibernate 3.5.1 final in a swing applicationand 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-最终

  • hibernate-commons-annotations-3.2.0.Final

  • dom4j- 1.6.1

  • slf4j-api-1.6.4

  • slf4j-log4j12- 1.6.4

  • 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)


推荐答案

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

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

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

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.

这篇关于java.lang.ClassNotFoundException:org.apache.log4j.Level的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 19:59