java.lang.NoClassDefFoundError while deploying a w

2019-08-23 05:23发布

问题:

I've built by Maven a war file that uses other war overlays as dependencies... The built was successful.

But while deploying to Jboss I get the following error:

11:27:49,054 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) .... nested exception is java.lang.NoClassDefFoundError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
        at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281) [spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) [spring-context-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        ........

So I've got java.lang.NoClassDefFoundError for class AnnotationMetadataReadingVisitor... based on the exception, I assume that the class appears more than once on the classpath.

I've verified that org.springframework.core.type.classreading.AnnotationMetadataReadingVisitor does exist on the classpath (in the war file it's in WEB-INF\lib\spring-core-3.2.1.RELEASE.jar).

But as far as I can see it's the only jar on my classpath that contains that class.

Any idea what I am missing here?

Here is the full content of the WEB-INF\lib of the war I'm trying to deploy:

activemq-all-5.5.1.jar
ant-1.7.0.jar
ant-launcher-1.7.0.jar
antlr-2.7.7.jar
antlr-3.3.jar
antlr-runtime-3.3.jar
aopalliance-1.0.jar
aspectjweaver-1.7.1.jar
axiom-api-1.2.12.jar
axiom-dom-1.2.12.jar
axiom-impl-1.2.12.jar
axis2-1.6.1.jar
axis2-adb-1.6.1.jar
axis2-adb-codegen-1.6.1.jar
axis2-ant-plugin-1.6.1.jar
axis2-clustering-1.6.1.jar
axis2-codegen-1.6.1.jar
axis2-corba-1.6.1.jar
axis2-fastinfoset-1.6.1.jar
axis2-java2wsdl-1.6.1.jar
axis2-jaxbri-1.6.1.jar
axis2-jaxws-1.6.1.jar
axis2-jibx-1.6.1.jar
axis2-json-1.6.1.jar
axis2-kernel-1.6.1.jar
axis2-metadata-1.6.1.jar
axis2-mtompolicy-1.6.1.jar
axis2-saaj-1.6.1.jar
axis2-transport-http-1.6.1.jar
axis2-transport-local-1.6.1.jar
axis2-xmlbeans-1.6.1.jar
bcel-5.1.jar
blitzer-1.0.9.jar
c3p0-0.9.1.1.jar
camel-core-2.4.0.jar
camel-xstream-2.4.0.jar
cdjai-1.0.jar
commons-beanutils-1.7.0.jar
commons-cli-1.2.jar
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-dbcp-1.4.jar
commons-digester-1.8.jar
commons-fileupload-1.2.1.jar
commons-httpclient-3.1.jar
commons-io-1.3.2.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-management-1.0.jar
commons-net-3.1.jar
commons-pool-1.5.4.jar
displaytag-1.2.jar
displaytag-export-poi-1.2.jar
drools-compiler-5.3.0.Final.jar
drools-core-5.3.0.Final.jar
ecj-3.5.1.jar
el-api-2.2.jar
el-impl-2.2.jar
FastInfoset-1.2.7.jar
freemarker-2.3.13.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.jar
geronimo-javamail_1.4_spec-1.6.jar
geronimo-jaxws_2.2_spec-1.0.jar
geronimo-jta_1.1_spec-1.1.jar
geronimo-saaj_1.3_spec-1.0.1.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
httpcore-4.0.jar
itext-1.3.jar
javaee-api-5.0-2.jar
javax.inject-1.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.7.jar
jaxb-xjc-2.1.7.jar
jaxen-1.1.1.jar
jaxws-tools-2.1.3.jar
jboss-j2se-200504122039.jar
jcl104-over-slf4j-1.4.2.jar
jettison-1.2.jar
jibx-bind-1.2.jar
jibx-run-1.2.jar
jsp-api-2.1.jar
jsr311-api-1.0.jar
jta-1.1.jar
juli-6.0.16.jar
junit-4.8.2.jar
knowledge-api-5.3.0.Final.jar
log4j-1.2.16.jar
mvel2-2.1.0.drools4.jar
neethi-2.0.1.jar
ognl-2.6.11.jar
ojdbc14-10.2.0.3.0.jar
p-my-web-app-legacy-1.0-SNAPSHOT-classes.jar
poi-3.2-FINAL.jar
primefaces-3.4.2.jar
quartz-2.0.2.jar
regexp-1.2.jar
servlet-api-2.5.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.4.2.jar
spring-aop-3.2.1.RELEASE.jar
spring-asm-3.1.4.RELEASE.jar
spring-aspects-3.2.1.RELEASE.jar
spring-beans-3.2.1.RELEASE.jar
spring-context-3.2.1.RELEASE.jar
spring-context-support-3.2.1.RELEASE.jar
spring-core-3.2.1.RELEASE.jar
spring-expression-3.2.1.RELEASE.jar
spring-instrument-3.2.1.RELEASE.jar
spring-jdbc-3.2.1.RELEASE.jar
spring-jms-3.2.1.RELEASE.jar
spring-orm-3.2.1.RELEASE.jar
spring-oxm-3.2.1.RELEASE.jar
spring-test-3.2.1.RELEASE.jar
spring-tx-3.2.1.RELEASE.jar
spring-web-3.2.1.RELEASE.jar
spring-webmvc-3.2.1.RELEASE.jar
standard-1.0.6.jar
stax-api-1.0.1.jar
stax2-api-3.0.1.jar
stringtemplate-3.2.1.jar
struts2-core-2.1.6.jar
struts2-dojo-plugin-2.2.3.1.jar
struts2-tiles-plugin-2.1.6.jar
tiles-api-2.0.6.jar
tiles-core-2.0.6.jar
tiles-jsp-2.0.6.jar
tiles-servlet-2.1.2.jar
tribes-6.0.16.jar
woden-api-1.0M9.jar
woden-impl-commons-1.0M9.jar
woden-impl-dom-1.0M9.jar
woodstox-core-asl-4.0.7.jar
wsdl4j-1.6.2.jar
wstx-asl-3.2.9.jar
xalan-2.7.0.jar
xml-resolver-1.2.jar
xmlbeans-2.3.0.jar
XmlSchema-1.4.7.jar
xpp3_min-1.1.4c.jar
xstream-1.3.1.jar
xwork-2.1.2.jar

回答1:

So you had a version conflict here

spring-aop-3.2.1.RELEASE.jar
spring-asm-3.1.4.RELEASE.jar
spring-aspects-3.2.1.RELEASE.jar
spring-beans-3.2.1.RELEASE.jar
spring-context-3.2.1.RELEASE.jar
spring-context-support-3.2.1.RELEASE.jar
spring-core-3.2.1.RELEASE.jar
spring-expression-3.2.1.RELEASE.jar
spring-instrument-3.2.1.RELEASE.jar
spring-jdbc-3.2.1.RELEASE.jar
spring-jms-3.2.1.RELEASE.jar
spring-orm-3.2.1.RELEASE.jar
spring-oxm-3.2.1.RELEASE.jar
spring-test-3.2.1.RELEASE.jar
spring-tx-3.2.1.RELEASE.jar
spring-web-3.2.1.RELEASE.jar
spring-webmvc-3.2.1.RELEASE.jar

other libraries are 3.2.1, spring-asm is 3.1.4. In general, spring jars should be of the same version.

Spring-asm library is bundled within spring-core in 3.2 series (source):

As of 3.2 M2 [..] we've eliminated the dedicated spring-asm jar in M2 in favor of including org.springframework.asm classes directly in spring-core.

So in this case, it should be left out.



回答2:

And, just to spell that out (for myself in the future), I had to add { transitive = false } to my BuildConfig.groovy file.

E.g.

grails.project.dependency.resolution = {
    plugins {
        ...
        compile(":spring-security-core:2.0-RC2")
        compile(":spring-security-facebook:0.15.1-CORE2"){ transitive = false }
        ...
    }
}