Run java -jar aspectj-[version].jar and perform the installation.
Add the bin directory of to your path to make it easier to run the AsjpectJ compiler ajc.
Add aspectjrt.jar to your classpath.
The goal of this example is to extend this simple class with logging functionality. Every time a method is called or exited, a message must be logged to stdout.
Test.java:
public class Test
{
public static void main(String []args) {
a();
}
public static void a() {
b();
}
public static void b() {
c();
}
public static void c() {
System.out.println("C reached!");
}
}
Notice that the original code in Test.java was not touched. But if you decompile Test.class with Jad, you’ll see why Test behaves the way it does, with the logging:
Get Started with AspectJ
Joris Van den BogaertTest.java:
TraceAspect.java: