我在使用maven在eclipse中构建一个方面项目时遇到了问题。当我通过eclipse运行maven“Run As> Maven build”时,我收到此消息:< ...> /Clazz.java:[5,32]错误:找不到符号。因此,看起来aspectj不是通过maven编织代码。
我解决了这个问题,直到在上面提到的类中有类和一个定义intertype属性的方面,如下所示:
public class Clazz {
public static void main(String[] args) {
System.out.println(new Clazz().string);
}
}
public aspect Aspect {
public String Clazz.string = "string";
}
pom.xml如下所示:
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:5)
问题似乎是maven-compiler-plugin
在你有一个AspectJ编译时不知道如何摆脱困境并抛出在ajc
有机会之前杀死构建的错误拉入ITD。我的解决方案是完全停用maven-compiler-plugin
并让ajc
处理.java
文件的编译:
<!-- disable compiler because compiler chokes on ITDs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
答案 1 :(得分:4)
实际上你不需要停用Maven编译器插件,但根据我发现的类似问题的人here,你需要做两件事:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<aspectj.version>1.8.1</aspectj.version>
</properties>
<!-- (...) -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>1.7</source>
<target>1.7</target>
<Xlint>ignore</Xlint>
<complianceLevel>1.7</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</verbose>
</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>
即。你需要
应该这样做。