Archive for the ‘AspectJ’ Category

Maven: Pom.xml and AspectJ

Monday, March 26th, 2012

In the Lib that has the aspect, add this to the pom.xml

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

.....


<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.6.7</version>
</dependency>

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.6.7</version>
</dependency>

Then, on the application that receive the aspect, need to have the failOnError:false to allow the mvn compiler to continue. Then, we weave the dependency “LibWithSomeAspects” in.

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <!-- Temporary fix for supporting aspectJ -->
    <failOnError>false</failOnError>
  </configuration>
</plugin>

<!-- AspecJ Compile -->
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>aspectj-maven-plugin</artifactId>
  <version>1.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <outxml>true</outxml>
    <showWeaveInfo>true</showWeaveInfo>
    <verbose>true</verbose>
    <weaveDependencies>
      <weaveDependency>
        <groupId>com.example</groupId>
        <artifactId>LibWithSomeAspects</artifactId>
      </weaveDependency>
    </weaveDependencies>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>test-compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<!-- /AspecJ Compile -->

AspectJ: Warning advice defined has not been applied [Xlint:adviceDidNotMatch]

Friday, November 13th, 2009

In Eclipse and AJDT, you will see the following warning if an advice has not been applied

advice defined in xxxx has not been applied [Xlint:adviceDidNotMatch]	xxx.class...

To remove this, add the @SuppressAjWarnings({“adviceDidNotMatch”}) on your advice methods

For example:

public aspect MyAspect{
  pointcut ...

  @SuppressAjWarnings({"adviceDidNotMatch"})
  Object around(Transactional transactional) : mylMethodExecution(transactional){
    ...
  }
}

AspectJ: Suppress Warnings adviceDidNotMatch

Tuesday, August 18th, 2009
@SuppressAjWarnings({"adviceDidNotMatch"})

See forum discussion