Weaving Java Binaries
Aspect weaving is a process of modifying binary .class
files after compilation in order to inject AOP advice at certain join points.
First of all, you annotate your classes and methods, and then compile. Then you run AspectJ weaver which modifies .class
files, producing new "weaved" versions of them.
Luckily, these steps can be automated. All you need to do to start using our AOP aspects is add these two artifacts to your pom.xml
:
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-aspects</artifactId> <version>0.26.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.6.12</version> <scope>runtime</scope> </dependency>
Then, you use jcabi-maven-plugin plugin which executes AspectJ weaver to modify your .class
files:
<project> <build> <plugins> <plugin> <groupId>com.jcabi</groupId> <artifactId>jcabi-maven-plugin</artifactId> <version>0.8</version> <executions> <execution> <goals> <goal>ajc</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Additional configuration for eclipse users.
That's it.