maven專案生成的war包在tomcat下執行報錯

張小凡vip發表於2014-11-19



maven專案在tomcat中執行 主要會有兩種錯誤:

一是依賴包衝突

二是slf4j包錯誤


如下:

資訊: Deploying web application archive D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT.war
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\javax.servlet-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\javax.servlet.jsp-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\jsp-api-2.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\servlet-api-2.3.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2014-11-18 17:17:01 org.apache.catalina.loader.WebappClassLoader validateJarFile
資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\tomcat-servlet-api-8.0.15.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class


嚴重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
	at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:272)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)



我們來分析原因和嘗試解決:

依賴包衝突

原因

Maven1中,需要把依賴所需要的包每個列出。這對於使用類似如Hibernate的使用者來說所操的心太多了,而且也不方便。在Maven2及以上版本中實現了傳遞依賴,如此對於Hibernate所依賴的包,Maven2會自動下載,開發人員只需關心Hibernate即可。所以可以看出列出所需要的每個jar是在maven1中的功能,Maven2以上版本認為自動下載是一種改進

       這樣就產生了一個問題:Maven2以上版本雖然把編譯時需要的jar都下載了,但並不是所有編譯需要的jar在打成war包後執行時也需要。所以也就發現有許多的jar是不需要的,以至war包比較大。還會產生衝突。

       類包衝突的一個很大的原因即產類包之間的間接依賴引起的。每個顯式宣告的類包都會依賴於一些其它的隱式類包,這些隱式的類包會被maven間接引入進來,因而可能造成一個我們不想要的類包的載入,嚴重的甚至會引起類包之間的衝突。


例如:

servlet-api.jar

資訊: validateJarFile(D:\tomcat7\webapps\ipFilterM-0.0.1-SNAPSHOT\WEB-INF\lib\servlet-api-2.3.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

造成這種情況的原因很可能是以下兩種情況:

一、專案的WEB-INF/lib下有servlet-api.jar,與Tomcat自帶的servlet-api.jar衝突了。

二、專案的WEB-INF/lib下有包含javax.servlet包的其他JAR包(如WebLogic 8.1的weblogic.jar),造成與Tomcat自帶的servlet-api.jar的衝突。

 

因為Tomcat的WebappClassLoader載入JAR包時會進行校驗,一旦發現上述衝突就會報出上面的異常。



解決方法

直接引用的包

要加上<scope>provided</scope>標籤

maven的dependency中有一個tag是<scope>option</scope>,其option有以下幾個值:

  compile, 預設值,適用於所有階段,會隨著專案一起釋出。

  provided,類似compile,期望JDK、容器或使用者會提供這個依賴。如servlet-api-2.3.jar。

  runtime, 在執行時使用,如JDBC驅動,適用執行和測試階段。   如plexus-utils-1.1.jar

  test     只在測試時使用,用於編譯和執行測試程式碼。不會隨專案釋出。如Junit-3.8.1.jar

  system, 類似provided,需要顯式提供包含依賴的jar,Maven不會在Repository中查詢它。

例如:

javax.servlet-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

<dependency>
			<groupId>org.glassfish</groupId>
			<artifactId>javax.servlet</artifactId>
			<version>3.0.1</version>			
		</dependency>


在pom.xml中是直接引用的,則改為:
<dependency>
			<groupId>org.glassfish</groupId>
			<artifactId>javax.servlet</artifactId>
			<version>3.0.1</version>
			<scope>provided</scope>
		</dependency>



間接引用包

間接衝突解決方法一新建一個provided衝突包

新建一個衝突包,加上<scope>provided</scope>標籤
例如:servlet-api-2.3.jar
在pom.xml中沒有它的資訊,是其它包間接引用了它
則我們新建如下:
	<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.3</version>
			<scope>provided</scope>
		</dependency>


間接衝突解決方法二把衝突包依賴排除在外

這種情況下同一型別的包只保留一個最高階的,其他有衝突的低階包全部要排除在外
例子如下:

專案裡要用到commons-logging。它有幾個依賴,其中有一個是servlet-api-2.3.jar。現在我需要用到容器內的servlet-api的非同步功能,編譯的時候卻總是自動引用預設的2.3版本。請問哪位有經驗處理這樣的衝突,可以遮蔽掉servlet-api-2.3.jar這個依賴包。

如果你的工程是用maven管理的話,可以在commons-logging的依賴裡把servlet-api-2.3去除掉,再加入你所需要的版本的servlet-api依賴。大概的例子如下: 
<!--如果你的工程是用maven管理的話,可以在commons-logging的依賴裡把servlet-api-2.3去除掉,再加入你所需要的版本的servlet-api依賴。大概的例子如下:  -->
<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
			<exclusions>
				<exclusion>
					<groupId>javax.servlet</groupId>
					<artifactId>servlet-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

<dependency>

			<groupId>org.mortbay.jetty</groupId>
			<artifactId>servlet-api-2.5</artifactId>
			<version>6.1.14</version>
			<scope>provided</scope>
		</dependency>
<!-- 指定scope為provided可以避免在釋出的時候把servlet-api包拷到lib目錄下。 -->


新增一個 衝突包的
provided的dependency   
針對每一個衝突包,要在它上級的包裡都加上exclusions把衝突包排除在外


新增和排除 都能在myeclipse中視覺化操作
如圖:






找間接依賴的包的兩個方法
在myeclipse的檢視中查詢



依賴樹
在cmd命令列中進入該專案的pom.xml所在位置:
輸入命令:
mvn dependency:tree



稍等一會我們就可以看到掃描出的依賴樹了,在裡面我們可以看到包的依賴關係


我掃描出的依賴樹如下:
.0.8/maven-model-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.
0.8/maven-model-2.0.8.pom (4 KB at 2.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project
/2.0.8/maven-project-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
2.0.8/maven-project-2.0.8.pom (3 KB at 4.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-setting
s/2.0.8/maven-settings-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
/2.0.8/maven-settings-2.0.8.pom (3 KB at 3.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile
/2.0.8/maven-profile-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
2.0.8/maven-profile-2.0.8.pom (2 KB at 4.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t-manager/2.0.8/maven-artifact-manager-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
-manager/2.0.8/maven-artifact-manager-2.0.8.pom (3 KB at 6.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposit
ory-metadata/2.0.8/maven-repository-metadata-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
ry-metadata/2.0.8/maven-repository-metadata-2.0.8.pom (2 KB at 4.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
registry/2.0.8/maven-plugin-registry-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-r
egistry/2.0.8/maven-plugin-registry-2.0.8.pom (2 KB at 4.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
api/2.0.8/maven-plugin-api-2.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-a
pi/2.0.8/maven-plugin-api-2.0.8.pom (2 KB at 3.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/2.1/plexus-utils-2.1.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/2.1/plexus-utils-2.1.pom (4 KB at 1.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
invoker/2.0.11/maven-invoker-2.0.11.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-i
nvoker/2.0.11/maven-invoker-2.0.11.pom (5 KB at 2.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mav
en-reporting-api/3.0/maven-reporting-api-3.0.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mav
en-reporting-impl/2.0.5/maven-reporting-impl-2.0.5.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-c
ore/1.0/doxia-core-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/commons-validator/commons-vali
dator/1.2.0/commons-validator-1.2.0.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
doxia-tools/1.0.2/maven-doxia-tools-1.0.2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-api/3.0/maven-reporting-api-3.0.jar (11 KB at 5.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/commons-beanutils/commons-bean
utils/1.7.0/commons-beanutils-1.7.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/reporting/mave
n-reporting-impl/2.0.5/maven-reporting-impl-2.0.5.jar (21 KB at 3.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/commons-digester/commons-diges
ter/1.6/commons-digester-1.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-d
oxia-tools/1.0.2/maven-doxia-tools-1.0.2.jar (41 KB at 6.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/commons-logging/commons-loggin
g/1.0.4/commons-logging-1.0.4.jar
Downloaded: https://repo.maven.apache.org/maven2/commons-logging/commons-logging
/1.0.4/commons-logging-1.0.4.jar (38 KB at 2.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/oro/oro/2.0.8/oro-2.0.8.jar
Downloaded: https://repo.maven.apache.org/maven2/oro/oro/2.0.8/oro-2.0.8.jar (64
 KB at 6.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-s
ink-api/1.0/doxia-sink-api-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
nk-api/1.0/doxia-sink-api-1.0.jar (10 KB at 16.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-s
ite-renderer/1.0/doxia-site-renderer-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-si
te-renderer/1.0/doxia-site-renderer-1.0.jar (46 KB at 38.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18
n/1.0-beta-7/plexus-i18n-1.0-beta-7.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-i18n
/1.0-beta-7/plexus-i18n-1.0-beta-7.jar (11 KB at 17.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-vel
ocity/1.1.7/plexus-velocity-1.1.7.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-velo
city/1.1.7/plexus-velocity-1.1.7.jar (8 KB at 12.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/velocity/velocity/1
.5/velocity-1.5.jar
Downloaded: https://repo.maven.apache.org/maven2/commons-beanutils/commons-beanu
tils/1.7.0/commons-beanutils-1.7.0.jar (185 KB at 5.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-d
ecoration-model/1.0/doxia-decoration-model-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/velocity/velocity/1.
5/velocity-1.5.jar (383 KB at 58.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-m
odule-apt/1.0/doxia-module-apt-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-de
coration-model/1.0/doxia-decoration-model-1.0.jar (48 KB at 30.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-m
odule-fml/1.0/doxia-module-fml-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-apt/1.0/doxia-module-apt-1.0.jar (46 KB at 48.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-m
odule-xdoc/1.0/doxia-module-xdoc-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-fml/1.0/doxia-module-fml-1.0.jar (19 KB at 20.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-m
odule-xhtml/1.0/doxia-module-xhtml-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-xdoc/1.0/doxia-module-xdoc-1.0.jar (28 KB at 29.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arc
hiver/2.3/plexus-archiver-2.3.jar
Downloaded: https://repo.maven.apache.org/maven2/commons-validator/commons-valid
ator/1.2.0/commons-validator-1.2.0.jar (89 KB at 2.1 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.9/plexus-utils-3.0.9.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-mo
dule-xhtml/1.0/doxia-module-xhtml-1.0.jar (22 KB at 22.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-m
anagement/1.2.1/file-management-1.2.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-co
re/1.0/doxia-core-1.0.jar (54 KB at 1.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
shared-io/1.1/maven-shared-io-1.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-arch
iver/2.3/plexus-archiver-2.3.jar (183 KB at 55.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/
2.0.6/plexus-io-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-ma
nagement/1.2.1/file-management-1.2.1.jar (37 KB at 12.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
dependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-s
hared-io/1.1/maven-shared-io-1.1.jar (39 KB at 14.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/asm/asm/3.3.1/asm-3.3.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-d
ependency-analyzer/1.4/maven-dependency-analyzer-1.4.jar (27 KB at 20.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
dependency-tree/2.1/maven-dependency-tree-2.1.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-io/2
.0.6/plexus-io-2.0.6.jar (57 KB at 29.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-util
/0.9.0.M2/aether-util-0.9.0.M2.jar
Downloaded: https://repo.maven.apache.org/maven2/asm/asm/3.3.1/asm-3.3.1.jar (43
 KB at 22.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
common-artifact-filters/1.4/maven-common-artifact-filters-1.4.jar
Downloaded: https://repo.maven.apache.org/maven2/commons-digester/commons-digest
er/1.6/commons-digester-1.6.jar (165 KB at 3.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-
invoker/2.0.11/maven-invoker-2.0.11.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-c
ommon-artifact-filters/1.4/maven-common-artifact-filters-1.4.jar (31 KB at 26.1
KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-d
ependency-tree/2.1/maven-dependency-tree-2.1.jar (59 KB at 20.3 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-i
nvoker/2.0.11/maven-invoker-2.0.11.jar (29 KB at 18.5 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-util/
0.9.0.M2/aether-util-0.9.0.M2.jar (131 KB at 19.3 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.9/plexus-utils-3.0.9.jar (227 KB at 11.2 KB/sec)
[INFO] ipFilterM:ipFilterM:war:0.0.1-SNAPSHOT
[INFO] +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:provided
[INFO] +- javax.activation:activation:jar:1.1:compile
[INFO] +- org.apache.james:apache-mime4j-core:jar:0.7.2:compile
[INFO] +- org.apache.ws.commons.axiom:axiom-api:jar:1.2.13:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-activation_1.1_spec:jar:1.1:comp
ile
[INFO] |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:comp
ile
[INFO] |  +- jaxen:jaxen:jar:1.1.3:compile
[INFO] |  \- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:comp
ile
[INFO] +- org.apache.ws.commons.axiom:axiom-impl:jar:1.2.13:compile
[INFO] |  \- org.codehaus.woodstox:wstx-asl:jar:3.2.9:compile
[INFO] +- org.apache.ws.commons.axiom:axiom-dom:jar:1.2.13:compile
[INFO] +- org.apache.axis2:axis2-adb:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-adb-codegen:jar:1.6.2:compile
[INFO] |  \- commons-cli:commons-cli:jar:1.2:compile
[INFO] +- ant:ant:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-codegen:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-fastinfoset:jar:1.6.2:compile
[INFO] |  \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.7:compile
[INFO] +- org.apache.axis2:axis2-java2wsdl:jar:1.6.2:compile
[INFO] |  \- org.apache.ant:ant:jar:1.7.0:compile
[INFO] +- org.apache.axis2:axis2-ant-plugin:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-clustering:jar:1.6.2:compile
[INFO] |  +- org.apache.tomcat:tribes:jar:6.0.16:compile
[INFO] |  \- org.apache.tomcat:juli:jar:6.0.16:compile
[INFO] +- org.apache.axis2:axis2-jibx:jar:1.6.2:compile
[INFO] |  +- org.jibx:jibx-bind:jar:1.2:compile
[INFO] |  \- org.jibx:jibx-run:jar:1.2:compile
[INFO] +- org.apache.axis2:axis2-json:jar:1.6.2:compile
[INFO] |  \- org.codehaus.jettison:jettison:jar:1.0-RC2:compile
[INFO] +- org.apache.axis2:axis2-kernel:jar:1.6.2:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-ws-metadata_2.0_spec:jar:1.1.2:c
ompile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile
[INFO] |  +- javax.servlet:servlet-api:jar:2.3:compile
[INFO] |  \- javax.ws.rs:jsr311-api:jar:1.0:compile
[INFO] +- org.apache.axis2:axis2-mtompolicy:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-saaj:jar:1.6.2:compile
[INFO] |  \- org.apache.geronimo.specs:geronimo-saaj_1.3_spec:jar:1.0.1:compile
[INFO] +- org.apache.axis2:axis2-soapmonitor-servlet:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-spring:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-transport-http:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-transport-local:jar:1.6.2:compile
[INFO] +- org.apache.axis2:axis2-xmlbeans:jar:1.6.2:compile
[INFO] |  +- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
[INFO] |  \- org.apache.ant:ant-launcher:jar:1.7.0:compile
[INFO] +- bcel:bcel:jar:5.1:compile
[INFO] |  \- regexp:regexp:jar:1.2:compile
[INFO] +- net.sf.jmatchparser:jMatchParser-icu4j-chardet:jar:0.1:compile
[INFO] |  \- com.ibm.icu:icu4j:jar:4.8.1.1:compile
[INFO] +- com.github.sebhoss:common-annotations:jar:1.0.0:compile
[INFO] |  \- com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] +- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- commons-discovery:commons-discovery:jar:0.4:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.3:compile
[INFO] +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- net.sourceforge.htmlcleaner:htmlcleaner:jar:2.2:compile
[INFO] |  \- org.jdom:jdom:jar:1.1:compile
[INFO] +- org.freemarker:freemarker:jar:2.3.19:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO] +- org.apache.httpcomponents:httpclient-cache:jar:4.2.5:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO] +- gov.nist.math:jama:jar:1.0.3:compile
[INFO] +- javassist:javassist:jar:3.11.0.GA:compile
[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.3:compile
[INFO] +- org.jsoup:jsoup:jar:1.7.2:compile
[INFO] +- junit:junit:jar:4.11:compile
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.apache.lucene:lucene-core:jar:4.3.1:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.10.1:compile
[INFO] +- org.apache.neethi:neethi:jar:3.0.2:compile
[INFO] |  \- org.codehaus.woodstox:woodstox-core-asl:jar:4.0.8:compile
[INFO] |     +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |     \- org.codehaus.woodstox:stax2-api:jar:3.0.2:compile
[INFO] +- ognl:ognl:jar:3.0.6:compile
[INFO] +- org.apache.poi:poi:jar:3.9:compile
[INFO] +- org.quartz-scheduler:quartz:jar:2.2.1:compile
[INFO] |  \- c3p0:c3p0:jar:0.9.1.1:compile
[INFO] +- org.quartz-scheduler:quartz-jobs:jar:2.2.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.5:compile
[INFO] +- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-commons:jar:1.5.0.RELEASE:compile

[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.2.0.RELEASE:compile

[INFO] +- org.springframework.data:spring-data-mongodb-cross-store:jar:1.2.0.REL
EASE:compile
[INFO] |  +- org.aspectj:aspectjrt:jar:1.7.1:compile
[INFO] |  +- cglib:cglib:jar:2.2:compile
[INFO] |  \- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Fin
al:compile
[INFO] +- org.springframework.data:spring-data-mongodb-log4j:jar:1.2.0.RELEASE:c
ompile
[INFO] +- org.aspectj:aspectjweaver:jar:1.8.0:compile
[INFO] +- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.0.0.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.0.0.RELEASE:compile
[INFO] +- org.apache.struts:struts2-core:jar:2.3.15.1:compile
[INFO] +- org.apache.struts:struts2-json-plugin:jar:2.3.15.1:compile
[INFO] +- org.apache.struts:struts2-spring-plugin:jar:2.3.15.1:compile
[INFO] +- org.apache.woden:woden-api:jar:1.0M9:compile
[INFO] +- org.apache.woden:woden-impl-commons:jar:1.0M9:compile
[INFO] +- org.apache.woden:woden-impl-dom:jar:1.0M9:compile
[INFO] +- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO] +- xalan:xalan:jar:2.7.0:compile
[INFO] +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] +- org.apache.ws.commons.schema:XmlSchema:jar:1.4.7:compile
[INFO] \- org.apache.struts.xwork:xwork-core:jar:2.3.15.1:compile
[INFO]    +- asm:asm:jar:3.3:compile
[INFO]    \- asm:asm-commons:jar:3.3:compile
[INFO]       \- asm:asm-tree:jar:3.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:27 min
[INFO] Finished at: 2014-11-17T19:37:06+08:00
[INFO] Final Memory: 14M/33M
[INFO] ------------------------------------------------------------------------
D:\workspace\ipFilterM>


根據以上方法依次解決每個包的依賴衝突後,該問題解決。


slf4j包錯誤

錯誤如下:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:319)
at com.alibaba.citrus.webx.context.WebxComponentsLoader.initWebApplicationContext(WebxComponentsLoader.java:117)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)


原因

slf4j錯誤本質上也是包的衝突錯誤,編譯時和執行時採用了不一樣的jar.它的報錯資訊說的是 在這個類中找不到對應的方法,這是因為 slf4j包不同的版本,方法名不一樣導致的。比如tomcat預設的使用某一版本的sjf4j包,但我們引入了一個新版本的包,這時候tomcat就會去找新版本的包,當然就找不到這個方法。

我們在myeclipse的pom.xml檢視中也能看到這樣的衝突,如圖:



那麼解決的方法跟上述的依賴包類似

解決方法

方案一

把衝突的包provided,看看依賴庫裡,只要是有slf4j字母的包全部provided,重新發布war後,war包解壓出來的工程lib中已經沒有slf4j字母的包了,那就ok了。

相關文章