Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


This tutorial tries to walk you through the idea of Aspects deployment we have introduced in AspectWerkz 1..
This tutorial is using AspectWerkz 2.0.
You will learn how to integrate aspects and aspects libraries as regular components in your J2EE environment through the help of META-INF/aop.xml and WEB-INF/aop.xml files.


I assume you have a Java 1.4 correctly installed.

Download the 12.0 AspectWerkz release (or latest RC) and unzip it into a relevant location. I will use C:\aw\aspectwerkz\
This tutorial is based on the 12.0 beta1 version of AspectWerkz (you need to move file after unziping since this beta release contains some extra aspectwerkz3 subdirectory etc.).

The latest distribution can be found here.


This is a standard Java class, and can be compiled with javac ... demoAOP\ to produce the regular ".class" file in the "target" directory. We need to link to the aspectwerkz jar due to this JoinPoint class that is used in the source code of the DemoAspect, so we should write
javac -classpath %ASPECTWERKZ_HOME%\lib\aspectwerkz-12.0-beta1.jar demoAOP\, but usage of the environment variable makes sense here to set the CLASSPATH:


Code Block
execution(public * *..*.*(..))

We carrfully exclude the package name of the aspect thus:

Code Block

execution(public * *..*.*(..)) && !within(demoAOP..*)

As a consequence, the following AOP XML descriptor will be used.
Write this file in C:\aw\tomcat\META-INF\aop.xml for now.

Code Block
<!DOCTYPE aspectwerkz PUBLIC

    <system id="webapp">
        <aspect class="demoAOP.DemoAspect">
	    <pointcut name="allPublic" expression="execution(public * *..*.*(..)) AND !within(demoAOP..*)"/>
            <advice name="trace" type="around" bind-to="allPublic"/>


Since I will not make any assumption on your JVM environment, I will skip the interesting details in this part and we will use a non-optimized but out-of-the-box solution that ships with the AspectWerkz distribution: the command line tool in ASPECTWERKZ_HOME/bin/aspectwerkz (read doc).

Note: for Tomcat 5.0.27 and after, please refer to the comments at the end of the article

Open the Tomcat startup script bin/catalina.bat (C:\aw\jakarta-tomcat-5.0.25\bin\catalina.bat).
The main idea is to set ASPECTWERKZ_HOME in this script and replace JAVA_HOME/bin/java with ASPECTWERKZ_HOME/bin/aspectwerkz.


Code Block
@REM ** Begin of AspectWerkz configuration **
set ASPECTWERKZ_HOME=C:\aw\aspectwerkz
set _EXECJAVA=%ASPECTWERKZ_HOME%\bin\aspectwerkz.bat
@REM ** we can add some more AspectWerkz option this way:
@REM due to an open issue in beta1 version - this is just an optimization option
set JAVA_OPTS=%JAVA_OPTS% -Daspectwerkz.jittransform.offdetails=truefalse
@REM ** End of AspectWerkz configuration **

rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda

For a complete understanding of the different options and other modes, refer to the AspectWerkz weaving schemes documentation.
Note that as a consequence of using the command line tool for simplicity here, we will run the Tomcat with -Xdebug JVM mode (with Java 1.4).

Do not startup Tomcat for now.

Aspect deployed in the application with a WEB-INF/aop.xml