Creating a new Ant build file

To create a new Ant build file for an AspectJ project:

  1. Either from the context menu or from the menu bar's File menu, select New > File.
  2. Call the file build.xml.
  3. Double click on the file to open in the Ant editor.
  4. Edit the file as below:


    <?xml version="1.0" encoding="UTF-8"?>

    <project name="My Project" default="build" basedir=".">

       <target name="init" depends="init.variables,init.taskdefs" />

       <target name="init.variables" description="init variables">
         <property name="plugins.dir" location="${basedir}/../../plugins" />
         <property name="aspectjrt.jar" location="${plugins.dir}/org.aspectj.runtime_1.5.0.20050610/aspectjrt.jar" />
         <property name="aspectjweaver.jar" location="${plugins.dir}/org.aspectj.weaver_1.5.0.20050610/aspectjweaver.jar" />
         <property name="ajde.jar" location="${plugins.dir}/org.aspectj.ajde_1.5.0.20050610/ajde.jar" />
       </target>

       <target name="init.taskdefs" depends="init.variables" unless="taskdefs.init">
         <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
           <classpath>
             <pathelement path="${ajde.jar}" />
           </classpath>
         </taskdef>
         <property name="taskdefs.init" value="true" />
       </target>

       <target name="build" depends="init" description="build spacewar example">
         <iajc destDir="${basedir}/bin" classpath="${aspectjrt.jar}" fork="true">
           <forkclasspath>
             <pathelement path="${plugins.dir}/org.eclipse.core.boot_3.1.0/boot.jar"/>
             <pathelement path="${plugins.dir}/org.eclipse.core.resources_3.1.0/resources.jar"/>
             <pathelement path="${plugins.dir}/org.eclipse.core.runtime_3.1.1/runtime.jar"/>
             <pathelement path="${plugins.dir}/org.eclipse.core.runtime.compatibility_3.1.0/compatibility.jar"/>
             <pathelement path="${plugins.dir}/org.apache.ant_1.6.5/lib/ant.jar"/>
             <pathelement path="${ajde.jar}" />
             <pathelement path="${aspectjweaver.jar}" />
           </forkclasspath>
           <srcdir>
             <pathelement path="src/" />
           </srcdir>
         </iajc>
       </target>

    </project>

  5. Note: The path to the 'plugins' directory may be different on your machine and you may need to add other paths to the classpath. Correct these to reflect the correct values. You will also need to change the version numbers as appropriate.

Please see the AspectJ language guide for more information on the iajc Ant task.

Related tasks

Creating an Ant build file for an AspectJ plug-in