使用maven / eclipse进行AspectJ编译会为org / aspectj / bridge / IMessageHolder抛出NoClassDefFoundError

时间:2015-02-24 13:51:31

标签: java eclipse maven aspectj

我最近在我的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之外运行mvn包(在linux盒子上)时,这很好用。我有两个同事,他们都能够在eclipse中进行maven包装(他们最近都升级了)。唯一的区别是他们经历了Juno的升级路径,我只是做了一个新的&#34;安装&#34;并指出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 个答案:

答案 0 :(得分:1)

您的Maven配置存在一些潜在问题:

  • 您使用AspectJ Maven Plugin 1.7,它使用编译器版本1.8.2。
  • 但您对AspectJ Runtime 1.7.3有依赖性。 (BTW,1.7.4是最新的1.7.x AspectJ版本。)
  • 您的字节码目标版本是1.8,但AspectJ Runtime 1.7.x不支持Java 8。

我通常做的是:

  • 确保编译器和运行时版本同步。我甚至覆盖了AspectJ Maven插件中的AspectJ Tools版本,只是为了100%确定我有最新的编译器修复。
  • 通常我也使用相同的源,目标和合规级别版本。它没有伤害。

您可以根据需要调整此示例:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.source-target.version>1.7</java.source-target.version>
    <aspectj.version>1.8.5</aspectj.version>
    <main-class>de.scrum_master.galileo.OpenbookCleaner</main-class>
</properties>

<!-- (...) -->

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
        <source>${java.source-target.version}</source>
        <target>${java.source-target.version}</target>
        <!-- IMPORTANT -->
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
        <!--<showWeaveInfo>true</showWeaveInfo>-->
        <source>${java.source-target.version}</source>
        <target>${java.source-target.version}</target>
        <Xlint>ignore</Xlint>
        <complianceLevel>${java.source-target.version}</complianceLevel>
        <encoding>${project.build.sourceEncoding}</encoding>
        <!--<verbose>true</verbose>-->
        <!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>-->
    </configuration>
    <executions>
        <execution>
            <!-- IMPORTANT -->
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>${aspectj.version}</version>
        </dependency>
    </dependencies>
</plugin>

<!-- (...) -->

<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>${aspectj.version}</version>
    <scope>runtime</scope>
</dependency>

<!-- (...) -->

看看它是否有帮助。