NoClassDefFoundError: org/slf4j/LoggerFactory和NoClassDefFoundError: org/apache/log4j/LogManager解决方法

1.如果运行程序出现错误:“Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory”,这是因为项目缺少slf4j-api.jar和slf4j-log4j12.jar这两个jar包导致的错误。

2.如果运行程序出现错误:“java.lang.NoClassDefFoundError: org/apache/log4j/LogManager”,这是因为项目缺少log4j.jar这个jar包

3.错误:“Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.MDC.getCopyOfContextMap()Ljava/util/Map”,这是因为jar包版本冲突造成的。

slf4j-log4j12.jar版本信息:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ceki
Build-Jdk: 1.5.0_06
Bundle-Description: The slf4j log4j-12 binding
Bundle-Version: 1.3.1
Implementation-Version: 1.4.2
Implementation-Title: slf4j-log4j12
Bundle-ManifestVersion: 2
Bundle-SymbolicName: slf4j.log4j12
Bundle-Name: slf4j-log4j12
Bundle-Vendor: SLF4J.ORG
Export-Package: org.slf4j.impl;version=1.3.1
Import-Package: org.slf4j;version="[1.3,1.4)", org.slf4j.spi;version="
[1.3,1.4)", org.slf4j.helpers;version="[1.3,1.4)", org.apache.log4j

slf4j-api.jar版本信息:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: ceki
Build-Jdk: 1.5.0_06
Bundle-Description: The slf4j API
Bundle-Version: 1.3.1
Implementation-Version: 1.4.2
Implementation-Title: slf4j-api
Bundle-ManifestVersion: 2
Bundle-SymbolicName: slf4j.api
Bundle-Name: slf4j-api
Bundle-Vendor: SLF4J.ORG
Export-Package: org.slf4j;version=1.3.1, org.slf4j.spi;version=1.3.1,
org.slf4j.helpers;version=1.3.1
Import-Package: org.slf4j.impl;version="[1.3,1.4)"

log4j.jar版本信息:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.3.1_18-b01 (Sun Microsystems Inc.)

Name: org/apache/log4j/
Implementation-Title: log4j
Implementation-Version: 1.2.14
Implementation-Vendor: "Apache Software Foundation"

后来将log4j.jar版本从上面的1.2.14换到1.2.11

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.4
Created-By: 1.4.2_06-b03 (Sun Microsystems Inc.)

Name: org/apache/log4j/
Implementation-Title: log4j
Implementation-Version: 1.2.11
Implementation-Vendor: "Apache Software Foundation"

就不再出现“Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.MDC.getCopyOfContextMap()Ljava/util/Map”错误了。

4.ActiveMQ错误:Wire format negociation timeout: peer did not send his wire format.

官方解释:http://activemq.apache.org/javaxjmsjmsexception-wire-format-negociation-timeout-peer-did-not-send-his-wire-format.html

我出现这样的错误主要是因为ActiveMQ与slf4j的版本有冲突,我原先使用的是以前一种用的slf4j-1.4。后来看apache-activemq-5.5.1\lib目录下有slf4j-api-1.5.11.jar、slf4j-log4j12-1.5.11.jar和log4j-1.2.14.jar。我想这几个jar应该是和ActiveMQ匹配的,就使用了这三个jar,最终错误解决。



 

 

posted @ 2012-02-20 15:55  xwdreamer  阅读(133169)  评论(1编辑  收藏  举报