I got it to work.

There was a problem in my pom.xml. I should have removed
aspectj-maven-plugin from the plugins section, leaving it only in
pluginManagement/plugins in my Main pom. I have also removed the
"<phase>process-sources</phase>" from plugin/executions/execution for
aspectj-maven-plugin.

Thanks for everyone who had a glance at my problem. :)


Em qua, 16 de set de 2015 às 09:50, <aspectj-users-requ...@eclipse.org>
escreveu:

> Send aspectj-users mailing list submissions to
>         aspectj-users@eclipse.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://dev.eclipse.org/mailman/listinfo/aspectj-users
> or, via email, send a message with subject or body 'help' to
>         aspectj-users-requ...@eclipse.org
>
> You can reach the person managing the list at
>         aspectj-users-ow...@eclipse.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of aspectj-users digest..."
>
>
> Today's Topics:
>
>    1. Pointcut matched but Aspect not woven in class
>       (Homero Cardoso de Almeida)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 16 Sep 2015 12:49:28 +0000
> From: Homero Cardoso de Almeida <homero...@gmail.com>
> To: aspectj-users@eclipse.org
> Subject: [aspectj-users] Pointcut matched but Aspect not woven in
>         class
> Message-ID:
>         <CAPv0ZwrsjJjP_wDJiRH9yLypJJg6DGg_GCKtKxutjLrJ1L=
> q...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi everyone,
>
> I'm a novice to AspectJ and I've been struggling for the past few days
> trying to weave an aspect at compile time with aspectj-maven-plugin. I
> could do it with a simple project, but not in my main project. From what I
> see in the maven build log, the pointcut is matched and advised by my
> aspect, but when I run the program the aspect code is not executed. I've
> decompiled my class and found that the closure class was created but never
> called from anywhere.
>
> This is my project structure;
>
> MainProject
>     |
>     +--- pom.xml
>     |
>     +--- ProjectA
>     |    |
>     |    +--- InterfaceA.java
>     |    +--- ClassA.java
>     |    +--- pom.xml
>     |
>     +--- AspectProject
>         |
>         +--- MyAspect.java
>         +--- pom.xml
>
> -----------------------------------------
> MainProject/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>myGroup</groupId>
> <artifactId>MainProject</artifactId>
> <version>1.0.5</version>
> <packaging>pom</packaging>
> <name>Main Project</name>
> <modules>
> <module>ProjectA</module>
> <module>AspectProject</module>
> </modules>
> <dependencies>
> <dependency>
> <groupId>org.aspectj</groupId>
> <artifactId>aspectjrt</artifactId>
> <version>1.8.2</version>
> </dependency>
> </dependencies>
> <dependencyManagement>
> <dependencies>
> <dependency>
> <groupId>myGroup</groupId>
> <artifactId>AspectProject</artifactId>
> <version>${project.version}</version>
> </dependency>
> </dependencies>
> </dependencyManagement>
> <build>
> <plugins>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>aspectj-maven-plugin</artifactId>
> <executions>
> <execution>
> <phase>process-sources</phase>
> <goals>
> <goal>compile</goal>
> <goal>test-compile</goal>
> </goals>
> </execution>
> </executions>
> <configuration>
> <source>1.7</source>
> <target>1.7</target>
> <complianceLevel>1.7</complianceLevel>
> <showWeaveInfo>true</showWeaveInfo>
> <verbose>true</verbose>
> </configuration>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-dependency-plugin</artifactId>
> <executions>
> <execution>
> <id>copy-dependencies</id>
> <phase>package</phase>
> <goals>
> <goal>copy-dependencies</goal>
> </goals>
> <configuration>
> <outputDirectory>C:\Output\</outputDirectory>
> <overWriteReleases>false</overWriteReleases>
> <overWriteSnapshots>false</overWriteSnapshots>
> <overWriteIfNewer>true</overWriteIfNewer>
> </configuration>
> </execution>
> </executions>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
> <version>3.1</version>
> <configuration>
> <source>1.7</source>
> <target>1.7</target>
> </configuration>
> </plugin>
> </plugins>
>
>
> <pluginManagement>
>
> <plugins>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>aspectj-maven-plugin</artifactId>
> <version>1.7</version>
> <executions>
> <execution>
> <phase>process-sources</phase>
> <goals>
> <goal>compile</goal>
> <goal>test-compile</goal>
> </goals>
> </execution>
> </executions>
> <configuration>
> <source>1.7</source>
> <target>1.7</target>
> <complianceLevel>1.7</complianceLevel>
> <showWeaveInfo>true</showWeaveInfo>
> <verbose>true</verbose>
> </configuration>
> </plugin>
> <!--This plugin's configuration is used to store Eclipse m2e settings
> only. It has no influence on the Maven build itself. -->
> <plugin>
> <groupId>org.eclipse.m2e</groupId>
> <artifactId>lifecycle-mapping</artifactId>
> <version>1.0.0</version>
> <configuration>
> <lifecycleMappingMetadata>
> <pluginExecutions>
> <pluginExecution>
> <pluginExecutionFilter>
> <groupId>
> org.codehaus.mojo
> </groupId>
> <artifactId>
> aspectj-maven-plugin
> </artifactId>
> <versionRange>
> [1.3,)
> </versionRange>
> <goals>
> <goal>compile</goal>
> <goal>test-compile</goal>
> </goals>
> </pluginExecutionFilter>
> <action>
> <execute />
> </action>
> </pluginExecution>
> </pluginExecutions>
> </lifecycleMappingMetadata>
> </configuration>
> </plugin>
> </plugins>
> </pluginManagement>
> </build>
> </project>
>
> -----------------------------------------
> ProjectA/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>
>
> <artifactId>ProjectA</artifactId>
> <name>Project A</name>
>
> <dependencies>
> <dependency>
> <groupId>myGroup</groupId>
> <artifactId>AspectProject</artifactId>
> </dependency>
> </dependencies>
>
> <build>
> <plugins>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>aspectj-maven-plugin</artifactId>
> <configuration>
> <aspectLibraries>
> <aspectLibrary>
> <groupId>myGroup</groupId>
> <artifactId>AspectProject</artifactId>
> </aspectLibrary>
> </aspectLibraries>
> </configuration>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-jar-plugin</artifactId>
> <version>2.3.1</version>
> <configuration>
> <outputDirectory>C:\Output\</outputDirectory>
> </configuration>
> </plugin>
> </plugins>
> </build>
>
> <parent>
> <groupId>myGroup</groupId>
> <artifactId>MainProject</artifactId>
> <version>1.0.5</version>
> <relativePath>../</relativePath>
> </parent>
>
> </project>
>
> -----------------------------------------
> ProjectA/InterfaceA.java
>
> public interface InterfaceA {
>     myOperation (String arg) throws Exception;
> }
>
> -----------------------------------------
> ProjectA/ClassA.java
>
> public class ClassA extends InterfaceA {
>     @Override
>     public Object myOperation (String arg) throws Exception {
>         //...
>     }
> }
>
> -----------------------------------------
> AspectProject/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>
> <parent>
> <groupId>myGroup</groupId>
> <artifactId>MainProject</artifactId>
> <version>1.0.5</version>
> <relativePath>../</relativePath>
> </parent>
>
> <artifactId>AspectProject</artifactId>
>
> <name>Aspects Project</name>
>
> <build>
> <plugins>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>aspectj-maven-plugin</artifactId>
> </plugin>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-jar-plugin</artifactId>
> <version>2.3.1</version>
> <configuration>
> <outputDirectory>C:\Output\</outputDirectory>
> </configuration>
> </plugin>
> </plugins>
>
> </build>
>
> <dependencies>
> <dependency>
> <groupId>org.aspectj</groupId>
> <artifactId>aspectjrt</artifactId>
> <version>1.8.2</version>
> </dependency>
> </dependencies>
> </project>
>
> -----------------------------------------
> AspectProject/Aspect.java
>
> @Aspect
> public class Aspect {
>
>     private void initializeObjects() {
>         //...
>     }
>
>     private void finalizeObjects() {
>         //...
>     }
>
>     @Around("execution(* myOperation(..))")
>     public Object intercept(ProceedingJoinPoint pjp) throws Throwable {
>         initializeObjects();
>         try {
>             Object ret = pjp.proceed();
>             return ret;
>         } catch (Exception e) {
>             e.printStackTrace();
>             throw e;
>         } finally {
>             finalizeObjects();
>         }
>     }
> }
>
> This is the output when I run maven install in AspectProject:
>
> [INFO] Scanning for projects...
> [INFO]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building AspectProject 1.0.5
> [INFO]
> ------------------------------------------------------------------------
> [INFO]
> [INFO] --- aspectj-maven-plugin:1.7:compile (default) @ AspectProject ---
> [INFO] Showing AJC message detail for messages of types: [error, warning,
> fail]
> [WARNING] advice defined in Aspect has not been applied
> [Xlint:adviceDidNotMatch]
>         C:\Workspace\MainProject\AspectProject\Aspect.java:##
>
> [INFO]
> [INFO] --- aspectj-maven-plugin:1.7:test-compile (default) @ AspectProject
> ---
> [WARNING] No sources found skipping aspectJ compile
>
> [INFO] MORE MAVEN STUFF FROM OTHER PLUGINS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 4.050 s
> [INFO] Finished at: 2015-09-16T08:37:17-03:00
> [INFO] Final Memory: 24M/228M
> [INFO]
> ------------------------------------------------------------------------
>
> This is the output when I run maven install in ProjectA:
>
> [INFO] Scanning for projects...
> [INFO]
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building Project A 1.0.5
> [INFO]
> ------------------------------------------------------------------------
> [INFO]
> [INFO] --- aspectj-maven-plugin:1.7:compile (default) @ ProjectA ---
> [INFO] Showing AJC message detail for messages of types: [error, warning,
> fail]
> [INFO] Join point 'method-execution(Object ClassA.myOperation(String arg))'
> in Type 'ClassA' (ClassA.java:###) advised by around advice from 'Aspect'
> (AspectProject-1.0.5.jar!Aspect.class(from Aspect.java))
> [INFO]
> [INFO] --- aspectj-maven-plugin:1.7:test-compile (default) @ ItemNeuronSAD
> ---
> [INFO] Showing AJC message detail for messages of types: [error, warning,
> fail]
> [WARNING] advice defined in Aspect has not been applied
> [Xlint:adviceDidNotMatch]
>
>
> C:\Path\to\Repo\myGroup\AspectProject\1.0.5\AspectProject-1.0.5.jar!\Aspect.class:0
>
> [INFO] MORE MAVEN STUFF FROM OTHER PLUGINS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] BUILD SUCCESS
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 11.390 s
> [INFO] Finished at: 2015-09-16T08:39:09-03:00
> [INFO] Final Memory: 36M/512M
> [INFO]
> ------------------------------------------------------------------------
>
> When I inspect my ProjectA.jar file with JD (http://jd.benow.ca/), I found
> that a new class was created for the closure (ClassA$AjcClosure1.class) and
> it calls a "ClassA.myOperation_aroundBody0(...)". However, there's no
> myOperation_aroundBody0 method woven into ClassA.
>
> I would be realy grateful if anyone could point me on what is going on and
> how I may fix this so the code is woven in the class.
>
> Thanks,
> Homero.
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> https://dev.eclipse.org/mailman/private/aspectj-users/attachments/20150916/891fb560/attachment.html
> >
>
> ------------------------------
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@eclipse.org
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> End of aspectj-users Digest, Vol 127, Issue 11
> **********************************************
>
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to