## Apt

### Description

Runs the annotation processor tool (apt), and then optionally compiles the original code, and any generated source code. This task requires Java1.5 or later

This task inherits from the Javac Task, and thus supports all of the same attributes, and subelements. In addition, it supports the following addition items:

### Parameters

Attribute | Description | Required
compile | After running the Apt, should the code be compiled. (see the `-nocompile` flag on the Apt executable) | No, defaults to false.
factory | The fully qualified classname of the AnnotationProcessFactory to be used to construct annotation processors. This represents the `-factory` command line flag of the Apt executable. | No
factorypathref | The reference id of the path used to find the classes needed by the AnnotationProcessorFactory (and the location of the factory itself). This represents the `-factorypath` flag on the Apt executable. | No
preprocessdir | The directory used for preprocessing. This is the directory where the generated source code will be place. This represents the `-s` flag on the Apt executable. | No

### Parameters specified as nested elements

#### factorypath

You can specify the path used to find the classes needed by the AnnotationProcessorFactory at runtime, using this element. It is represents as a generic path like structure. This represents the `-factorypath` flag on the Apt executable.

#### option

Used to represent a generic option to pass to Apt. This represents the `-A` flag on the Apt executable. You can specify zero or more `<option>` elements.

Attribute | Description | Required
name | The name of the option | Yes.
value | The value to set the option to | Yes.

### Examples

      <apt srcdir="${src}"
             destdir="${build}"
             classpath="xyz.jar"
             debug="on"
             compile="true"
             factory="com.mycom.MyAnnotationProcessorFactory"
             factorypathref="my.factorypath.id"
             preprocessdir="${preprocess.dir}">
        </apt>

compiles all `.java` files under the `${src}` directory, and stores the `.class` files in the `${build}` directory. The classpath used includes `xyz.jar`, and compiling with debug information is on. It also forces the generated source code to be compiled. The generated source code will be placed in `${preprocess.dir}` directory, using the class `com.mycom.MyAnnotationProcessorFactory` to supply AnnotationProcessor instances.

### Notes

The "compiler" attribute is ignored, as it is forced to use the Apt compiler

Using the Apt compiler with the "compile" option set to "true" forces you to use Sun's Apt compiler, which will use the JDK's Javac compiler. If you wish to use another compiler, you will first need run the Apt processor with the "compile" flag set to "false", and then use a `<javac>` task to compile first your original source code, and then the generated source code:

      <Apt srcdir="${src}"
             destdir="${build}"
             classpath="xyz.jar"
             debug="true"
             compile="false"
             factory="com.mycom.MyAnnotationProcessorFactory"
             factorypathref="my.factorypath.id"
             preprocessdir="${preprocess.dir}">
        </apt>

        <javac srcdir="${src}"
             destdir="${build}"
             classpath="xyz.jar"
             debug="on"/>

        <javac srcdir="${preprocess.dir}"
             destdir="${build}"
             classpath="xyz.jar"
             debug="true"/>

This may involve more build file coding, but the speedup gained from switching to jikes may justify the effort.

Copyright © 2004 The Apache Software Foundation. All rights Reserved.