Recipe2.9.Building an AspectJ Project Using Ant


Recipe 2.9. Building an AspectJ Project Using Ant

Problem

You want to compile an AspectJ project using Ant.

Solution

Use the tasks included in the AspectJ toolkit to build your project using Ant.

Discussion

The Ant build.xml configuration file in Example 2-6 shows an example for how to call upon the additional AspectJ Ant tasks.

Example 2-6. An Ant configuration file that uses the AspectJ tasks
<?xml version="1.0" encoding="UTF-8"?> <project basedir="." default="compile" name="test">     <property name="src" value="src"/>     <property name="build" value="build"/>     <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.        properties">         <classpath>             <pathelement location="%ASPECTJ_INSTALLATION%/lib/                aspectjtools.jar"/>         </classpath>     </taskdef>     <target name="compile">         <mkdir dir="${build}"/>         <iajc destdir="${build}" sourceroots="${src}">             <classpath>                 <pathelement location="%ASPECTJ_INSTALLATION%/                    lib/aspectjrt.jar"/>             </classpath>         </iajc>     </target> </project>

Here is what Example 2-6 does:

  1. Defines a new task using the AspectJ task properties

  2. Specifies the location of the aspectjtools.jar

  3. Declares a build target that compiles the project using the iajc task that in turn relies upon the aspectjrt.jar to execute

See Also

Ant: The Definitive Guide by Jesse Tilly and Eric M. Burke (O'Reilly); the Jakarta Ant online manual at http://jakarta.apache.org/ant/manual/index.html.



AspectJ Cookbook
Aspectj Cookbook
ISBN: 0596006543
EAN: 2147483647
Year: 2006
Pages: 203
Authors: Russ Miles

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net