AspectJ and Maven

I am trying to get AspectJ to work in an existing project (in fact, I know little about this project because it was not important).

We decided to use weaving at boot time to avoid using ajc

Since I'm new to AspectJ, I created the first example project with some classes and the logging aspect:

@Aspect
public class LoggingAspect {

    @Pointcut("call(public de.test.beans.IPerson+.*(..))")
    public void logExecutions(JoinPoint jp) {}

    @Before("logExecutions(jp)")
    public void beforeExecutions(JoinPoint jp) {
        BeforeExecutionLog log = new BeforeExecutionLog(jp);
        System.out.println(log);                
    }

    @AfterReturning(pointcut = "logExecutions(jp)", returning = "ret")
    public void afterExecutions(JoinPoint jp, Object ret) {
        AfterExecutionLog log = new AfterExecutionLog(jp, ret);        
        System.out.println(log);        
    }    

}

It works great, everything is fine.

As a next step, I tried using AspectJ and Maven together. I changed the logging aspect a bit (package only).

According to the code from the book "AspectJ in Action" I changed our maven pom.xml

       <dependencies>
            ...
        <dependency>
           <groupId>org.aspectj</groupId>
           <artifactId>aspectjrt</artifactId>
           <version>1.6</version>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.12.M1</version>
        </dependency>       
       </dependencies>
        <plugin>                                                 
            <groupId>org.codehaus.mojo</groupId>            
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <executions>                                         
                <execution>                                      
                    <goals>                                      
                        <goal>compile</goal>                     
                    </goals>                                     
                    <configuration>                              
                        <source>1.5</source>                     
                        <target>1.5</target>                     
                    </configuration>                             
                </execution>                                     
            </executions>                                        
        </plugin>   

But if I try to call mvn clean install , I get thousands of errors, and the first one is:

[ERROR] Syntax error on token "call(public xxx.yyy.zzz.api.Service+.*(..))", "name pattern" expected
[ERROR] Method annotated with @Pointcut() for abstract pointcut must be abstract

There are also the following errors:

[ERROR] The method xyz() of type zyx must override a superclass method

, , .

- , ?

UPD:

.

+3
3

, , , , pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.test</groupId>
    <artifactId>test2</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.6.11</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
+2

, -.

[ERROR] The method xyz() of type zyx must override a superclass method

, javac ver1.5 @Override , java.

public interface A { void someMethod(); }
public class B implements A {
  @Override
  public void someMethod() {
    doSomething();
  }
}

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>

+2

: . asterix :

@Pointcut("call(public * de.test.beans.IPerson+.*(..))")
0

All Articles