如何使用 Java 7 和 maven 启用 aspectj 编译时编织 [英] How to enable aspectj compile time weaving with Java 7 and maven
问题描述
我有一个项目,目前使用 java 6 和编译时编织.我们使用以下 pom 来启用 spring 方面和我们自己的方面:
I have a project which currently works with java 6 and compile time weaving. We use the following pom to enable spring aspects and our own ones:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.6</source>
<target>1.6</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.6</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
我尝试了各种配置,但无法使其与 java 7 一起使用.如果有人可以分享一个工作的 pom 或领导,那就太好了.
I've tried various configuration but can't make it work with java 7. If someone could share a working pom or leads it would be great.
推荐答案
在移动到 aspectjtools 1.7.0 版后,它工作正常.此外,您需要将版本参数作为 -1.7
传递给编译器(使用 target
参数会导致问题).如果有人需要更多详细信息,请发表评论,我会添加更多配置特定信息.
您可以从这里获取一个工作示例:Spring、AspectJ 和 Maven 示例
这是来自 pom 的工作插件定义(compiler-version="1.7", aspectj.version="1.7.0")
After moving to version 1.7.0 of the aspectjtools it works fine. In addition you need to pass the compiler the version parameter as -1.7
(using the target
parameter caused problems). If someone needs more details leave a comment and I'll add more configuration specific information.
You can take a working example from here: Spring, AspectJ and Maven example
Here is the working plugin definition from the pom (compiler-version="1.7", aspectj.version="1.7.0")
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${compiler.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>false</verbose>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
这篇关于如何使用 Java 7 和 maven 启用 aspectj 编译时编织的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!