Getting Started

APT in Eclipse

The APT plugin adds Java 5 annotation processing support to Eclipse, by running annotation processors written to use the Mirror APIs inside Eclipse.

These annotation processors will then get triggered as you type inside Eclipse, provide errors and warnings directly inside the editor, and producing normal build artifacts just as if you were running Sun's apt tool from the commandline.

For more detailed information about how the plugin works, you can view the JDT-APT project web site.

Turning on Annotation Processing

You must have your project's compiler configured to use Java 5.0-level compliance in the preferences, under Java->Compiler:

Screenshot of Compiler preference page

Next you need to enable annotation processing under Java->Compiler->Annotation Processing:

Screenshot of Annotation Processing properties page

In this dialog you can also specify the generated source directory if desired, and provide any processor options that are necessary.

Note: "-Aclasspath" and "-Asourcepath" options are automatically passed to all your processors by eclipse, so it is unnecessary to provide those.

Adding Annotation Processors

You can add annotation processors to your project under Java->Compiler->Annotation Processing->Factory Path:

Screenshot of Factory Path properties page

Factory Path and Source Control

The factory path is similar to the classpath in the way it interacts with source control. In order to avoid hard-coding paths to factory jars, you can either use project-relative jars via the "Add Jars..." button, or use a classpath variable via the "Add Variable..." button.

Processor Options and Source Control

You may need to use paths as some of the options passed to your annotation processors. Again, by avoiding hard-coding of absolute paths you'll be able to share your configuration in source control.

To do this, we support classpath variables inside of processor options. Variables must be delimited on both sides by %, and must be the first segment of a path.

So, if FOO is a classpath variable that points to d:/foo, then %FOO%/bar.txt will resolve to d:/foo/bar.txt. Classpath resolution depends on the existence of the classpath variable; if it doesn't exist, the raw string will be added to the environment options. However, bar.txt (in this example) does not need to exist.

The reserved variable ROOT is given special meaning: it is the workspace root, and introduces a project resource. So, for instance, if quux is the name of a project, then %ROOT%/quux will resolve to the absolute path of quux and % ROOT%/quux/.classpath will resolve to the absolute path to quux/.classpath. When using ROOT, the first segment of the path must actually exist: in the example, the project quux must exist, but .classpath need not.