使用Maven进行AspectJ编译会抛出java.lang.NoClassDefFoundError:org/aspectj/bridge/IMessageHolder [英] AspectJ compilation with maven throws java.lang.NoClassDefFoundError: org/aspectj/bridge/IMessageHolder
问题描述
尝试编译我的Aspectj项目时收到以下错误.
I get the following error when trying to compile my aspectj project.
[INFO] --- aspectj-maven-plugin:1.4:compile (default) @ jetserver ---
Feb 2, 2012 7:33:31 PM org.sonatype.guice.bean.reflect.LoadedClass
WARNING: Error injecting: org.codehaus.mojo.aspectj.AjcCompileMojo
java.lang.NoClassDefFoundError: org/aspectj/bridge/IMessageHolder
at java.lang.Class.getDeclaredConstructors0(Native Method)
[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.4:compile (default) on project game-server: Execution default of goal org.codehaus.mojo:aspectj-maven-plugin:1.4:compile failed: Unable to load the mojo 'compile' in the plugin 'org.codehaus.mojo:aspectj-maven-plugin:1.4'. A required class is missing: org/aspectj/bridge/IMessageHolder
pom的相关部分粘贴在下面.有什么主意我为什么会出现此错误?
The relevant part of pom is pasted below. Any ideas why I get this error?
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.11</version>
</dependency>
</dependencies>
<configuration>
<source>1.6</source>
<complianceLevel>1.6</complianceLevel>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<target>1.6</target>
<!-- The following sets up aspectj weaving path. jetserver jar has the
compiled aspect which is used to weave classes in this app -->
<aspectLibraries>
<aspectLibrary>
<groupId>org.menacheri</groupId>
<artifactId>jetserver</artifactId>
<version>0.1</version>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
推荐答案
好像是1.6.11版存在问题.当我将其修改为1.6.1时,错误消失了.
Looks like there was an issue with version 1.6.11. When I modified this to 1.6.1 the error went away.
我的pom现在看起来像
My pom now looks like
依赖项:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.1</version>
</dependency>
插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<configuration>
<source>1.6</source>
<complianceLevel>1.6</complianceLevel>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<target>1.6</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
如果您使用的是eclipse,则以下maven-eclipse-plugin配置允许java src文件夹中的* .aj文件没有问题,并且在执行mvn clean时不会清除eclipse项目的ajdt属性.
If you are using eclipse, the following maven-eclipse-plugin configuration allows the *.aj files in java src folders without issue and does not clean away the ajdt properties of the eclipse project when doing a mvn clean.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<ajdtVersion>1.6</ajdtVersion>
<additionalProjectnatures>
<projectnature>org.eclipse.ajdt.ui.ajnature</projectnature>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
<projectnature>org.eclipse.wst.common.project.facet.core.nature</projectnature>
</additionalProjectnatures>
<!-- Source includes is necessary to allow aj files in the java
folder, else eclipse may throw a filtering exception -->
<sourceIncludes>
<sourceInclude>**/*.aj</sourceInclude>
</sourceIncludes>
<!-- Download sources will make maven download and attach source files
where available -->
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
这篇关于使用Maven进行AspectJ编译会抛出java.lang.NoClassDefFoundError:org/aspectj/bridge/IMessageHolder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!