使用maven/eclipse的java AspectJ编译会为org/AspectJ/bridge/IMessageHolder抛出NoClassDefFoundError
我最近在Windows 7上从eclipse Juno升级到Luna,我的aspectj编译有问题。我得到了这个错误:
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.7:compile (default) on project RSADirectoryUtilities: Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.7:compile failed: A required class was missing while executing org.codehaus.mojo:aspectj-maven-plugin:1.7:compile: org/aspectj/bridge/IMessageHolder
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:aspectj-maven-plugin:1.7
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/DJC/.m2/repository/org/codehaus/mojo/aspectj-maven-plugin/1.7/aspectj-maven-plugin-1.7.jar
[ERROR] urls[1] = file:/C:/Users/DJC/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar
[ERROR] urls[2] = file:/C:/Users/DJC/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[3] = file:/C:/Users/DJC/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[4] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar
[ERROR] urls[5] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.jar
[ERROR] urls[6] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-logging-api/1.1/doxia-logging-api-1.1.jar
[ERROR] urls[7] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-site-renderer/1.1.2/doxia-site-renderer-1.1.2.jar
[ERROR] urls[8] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-core/1.1.2/doxia-core-1.1.2.jar
[ERROR] urls[9] = file:/C:/Users/DJC/.m2/repository/xerces/xercesImpl/2.8.1/xercesImpl-2.8.1.jar
[ERROR] urls[10] = file:/C:/Users/DJC/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
[ERROR] urls[11] = file:/C:/Users/DJC/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar
[ERROR] urls[12] = file:/C:/Users/DJC/.m2/repository/commons-codec/commons-codec/1.2/commons-codec-1.2.jar
[ERROR] urls[13] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-decoration-model/1.1.2/doxia-decoration-model-1.1.2.jar
[ERROR] urls[14] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-module-xhtml/1.1.2/doxia-module-xhtml-1.1.2.jar
[ERROR] urls[15] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/doxia/doxia-module-fml/1.1.2/doxia-module-fml-1.1.2.jar
[ERROR] urls[16] = file:/C:/Users/DJC/.m2/repository/org/codehaus/plexus/plexus-i18n/1.0-beta-7/plexus-i18n-1.0-beta-7.jar
[ERROR] urls[17] = file:/C:/Users/DJC/.m2/repository/org/codehaus/plexus/plexus-velocity/1.1.7/plexus-velocity-1.1.7.jar
[ERROR] urls[18] = file:/C:/Users/DJC/.m2/repository/org/apache/velocity/velocity/1.5/velocity-1.5.jar
[ERROR] urls[19] = file:/C:/Users/DJC/.m2/repository/oro/oro/2.0.8/oro-2.0.8.jar
[ERROR] urls[20] = file:/C:/Users/DJC/.m2/repository/commons-collections/commons-collections/3.2/commons-collections-3.2.jar
[ERROR] urls[21] = file:/C:/Users/DJC/.m2/repository/org/apache/maven/reporting/maven-reporting-impl/2.1/maven-reporting-impl-2.1.jar
[ERROR] urls[22] = file:/C:/Users/DJC/.m2/repository/commons-validator/commons-validator/1.2.0/commons-validator-1.2.0.jar
[ERROR] urls[23] = file:/C:/Users/DJC/.m2/repository/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar
[ERROR] urls[24] = file:/C:/Users/DJC/.m2/repository/commons-digester/commons-digester/1.6/commons-digester-1.6.jar
[ERROR] urls[25] = file:/C:/Users/DJC/.m2/repository/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar
[ERROR] urls[26] = file:/C:/Users/DJC/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar
[ERROR] urls[27] = file:/C:/Users/DJC/.m2/repository/org/aspectj/aspectjtools/1.8.2/aspectjtools-1.8.2.jar
[ERROR] urls[28] = file:/C:/Program%20Files/Java/jdk1.8.0_31/jre/../lib/tools.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.aspectj.bridge.IMessageHolder
我的pom看起来像这样:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<!-- use this goal to weave all your main classes -->
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<complianceLevel>1.8</complianceLevel>
<target>1.8</target>
<source>1.6</source>
<verbose>true</verbose>
</configuration>
</plugin>
有几件有趣的事需要注意。当我在eclipse之外(在linux机器上)运行mvn包时,这种方法很好用。我有两个同事,他们都能在eclipse中编写软件包(他们最近也都升级了)。唯一的区别是,他们在Juno中进行了升级,我只是进行了一次新的“安装”,并指向Luna和我的工作区(它升级了)。我一个接一个地检查插件,试图找出它们的安装和我的安装之间的差异,但这并没有解决这个问题。我的点子快用完了
这个solution对我来说似乎过时了,不起作用
运行mvn依赖关系:树产量
[INFO] Building xxxDirectoryUtilities 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.3:tree (default-cli) @ xxxDirectoryUtilities ---
[INFO] xxxDirectoryUtilities:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.4:test
[INFO] +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.springframework:spring-context:jar:2.5.6:compile
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-core:jar:2.5.6:compile
[INFO] +- org.springframework:spring-tx:jar:2.5.6:compile
[INFO] +- org.springframework:spring-beans:jar:2.5.6:compile
[INFO] +- org.springframework.ldap:spring-ldap-core:jar:1.3.0.RELEASE:compile
[INFO] | \- commons-lang:commons-lang:jar:2.1:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.7.3:compile
[INFO] +- org.aspectj:aspectjrt:jar:1.7.3:compile
[INFO] +- xxxLoggingUtilities:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] +- xxxCryptographyUtils:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- org.jasypt:jasypt-spring2:jar:1.9.1:compile
[INFO] | \- org.jasypt:jasypt:jar:1.9.1:compile
[INFO] \- xxx:UnifiedSpringResourceFiles:jar:0.0.1-SNAPSHOT:compile
[INFO] \- org.springframework:spring:jar:2.5.6:compile
# 1 楼答案
Maven配置有几个潜在问题:
我通常做的是:
您可以根据需要调整此样本:
看看是否有帮助