This tutorial does not explain AOP, however if your new to the idea of AOP, then please check out JavaWorld's series of articles to get you started.
Download the latest release and unzip it into the relevant location. This tutorial is based on 0.10.
The latest distribution can be found here.
After installation you need to set the
ASPECTWERKZ_HOME environment variable to point to the installation directory. This is because quite a few of the scripts use this to find the required libraries. How this variable is set depends on you OS. Since I'm using Linux I've amended my
.bashrc file, windows users could do this by using the control panel.
The Test Application
Now we've installed aspectwerkz, we need a test application into which to weave our aspects. As is the tradition, I'm going to use the standard HelloWorld application.
This is simply a standard Java application, and can be compiled with
javac -d target HelloWorld.java
Writing the Aspect
Next we need to develop the aspect which will contain the code to be weaved into our HelloWorld class. In this example I'm going to output a statement before and after the greet method is called.
Notice the signature of the aspect methods. They need to take this
JoinPoint argument otherwise the AspectWerkz weaver won't be able to identify the method when the aspect is weaved in, (and can leave you scratching your head as to why the weaving isn't working!).
To compile this aspect class you'll need to include the
aspectwerkz-0.10.jar in the classpath, i.e.
javac -d target -classpath $ASPECTWERKZ_HOME/lib/aspectwerkz-0.10.jar MyAspect.java