Ajc10 (ajc)

This task handles the same arguments as those used by the AspectJ 1.0 task. This should permit those with existing build scripts using the Ajc Ant task to continue using the same scripts when compiling with 1.1. This will list any use of options no longer supported in 1.1 (e.g., lenient, strict, workingdir, preprocess, usejavac,...), and does not provide access to the new features of AspectJ 1.1. (Developers using AspectJ 1.1 only should upgrade their scripts to use AjcTask instead. This will not work for AspectJ 1.2 or later.)

Ajc10 (ajc) Options

Most attributes and nested elements are optional. The compiler requires that the same version of aspectjrt.jar be specified on the classpath, and that some sources be be specified (using one or more of argfiles and srcdir (with patterns)).

Boolean parameters default to false unless otherwise stated.

Table 2.6. AjcTask (ajc) options for specifying sources

AttributeDescription

srcdir

The base directory of the java files. See

destdir

The target directory for the output .class files

includes

Comma-separated list of patterns of files that must be included. No files are included when omitted.

includesfile

The path to a file containing include patterns.

excludes

Comma-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted.

excludesfile

The path to a file containing exclude patterns.

defaultexcludes

If true, then default excludes are used. Default excludes are used when omitted (i.e., defaults to true).

classpath, classpathref

The classpath to use, optionally given as a reference to a classpath Path element defined elsewhere.

bootclasspath, bootclasspathref

The bootclasspath to use, optionally given as a reference to a bootclasspath Path element defined elsewhere.

extdirs

Paths to directories containting installed extensions.

debug

If true, emit debug info in the .class files.

deprecation

If true, emit messages about use of deprecated API.

verbose

Emit compiler status messages during the compile.

version

Emit version information and quit.

failonerror

If true, throw BuildException to halt build if there are any compiler errors. If false, continue notwithstanding compile errors. Defaults to true.

source

Value of -source option - ignored unless 1.4.

Table 2.7. Parameters ignored by the old ajc taskdef, but now supported or buggy

AttributeDescriptionSupported?

encoding

Default encoding of source files.

yes

optimize

Whether source should be compiled with optimization.

yes?

target

Generate class files for specific VM version, one of [1.1 1.2].

yes

depend

Enables dependency-tracking.

no

includeAntRuntime

Whether to include the Ant run-time libraries.

no

includeJavaRuntime

Whether to include the run-time libraries from the executing VM.

no

threads

Multi-threaded compilation

no

The following table shows that many of the unique parameters in AspectJ 1.0 are no longer supported.

Table 2.8. Parameters unique to ajc

AttributeDescription

X

comma-delimited list of extended (-X...) options, entered without -X (e.g., X="lint" for -Xlint).

emacssym

Generate symbols for Emacs IDE support.

argfiles

A comma-delimited list of argfiles that contain a line-delimited list of source file paths (absolute or relative to the argfile).

argfiles - argument list files

An argument file is a file (usually {file}.lst) containing a list of source file paths (absolute or relative to the argfile). You can use it to specify all source files to be compiled, which ajc requires to avoid searching every possible source file in the source path when building aspects. If you specify an argfile to the ajc task, it will not include all files in any specified source directory (which is the default behavior for the Javac task when no includes are specified). Conversely, if you specify excludes, they will be removed from the list of files compiled even if they were specified in an argument file.

The compiler also accepts arguments that are not source files, but the IDE support for such files varies, and Javac does not support them. Be sure to include exactly one argument on each line.

Ajc10 parameters specified as nested elements

This task forms an implicit FileSet and supports all attributes of <fileset> (dir becomes srcdir) as well as the nested <include>, <exclude>, and <patternset> elements. These can be used to specify source files.

ajc's srcdir, classpath, bootclasspath, extdirs, and jvmarg attributes are path-like structures and can also be set via nested <src>, <classpath>, <bootclasspath>, <extdirs>, and <jvmargs> elements, respectively.

Sample of ajc task

Following is a declaration for the ajc task and a sample invocation that uses the ajc compiler to compile the files listed in default.lst into the dest dir:

		
<project name="example" default="compile" >
  <taskdef name="ajc"
    classname="org.aspectj.tools.ant.taskdefs.Ajc10" >
    <!-- declare classes needed to run the tasks and tools -->
    <classpath>
      <pathelement location="${home.dir}/tools/aspectj/lib/aspectjtools.jar"/>
    </classpath>
  </taskdef>

  <target name="compile" >
    <mkdir dir="dest" />
    <ajc destdir="dest" argfiles="default.lst" >
      <!-- declare classes needed to compile the target files -->
      <classpath>
        <pathelement location="${home.dir}/tools/aspectj/lib/aspectjrt.jar"/>
      </classpath>
    </ajc>
  </target>
</project>

		

This build script snippet

				
		  <ajc srcdir="${src}"
		       destdir="${build}"
		       argfiles="demo.lst"
		  />

		

compiles all .java files specified in the demo.lst and stores the .class files in the ${build} directory. Unlike the Javac task, the includes attribute is empty by default, so only those files specified in demo.lst are included.

This next example

				
		  <ajc srcdir="${src}"
		       destdir="${build}"
		       includes="spacewar/*,coordination/*"
		       excludes="spacewar/Debug.java"
		  />

		

compiles .java files under the ${src} directory in the spacewar and coordination packages, and stores the .class files in the ${build} directory. All source files under spacewar/ and coordination/ are used, except Debug.java.

See ../examples/build.xml for an example build script.