天天看點

[Log4j基礎]-- 缺少log4j包或包版本沖突報錯

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​​