Java 1.5 annotation processors and Netbeans

Netbeans has great support for annotation processors in editor, but it’s only available if you’re developing Java 1.6 application. But because Netbeans is using standard Ant scripts as it’s build system you can easily integrate 1.5 annotation processors with it. What you have to do is edit project build.xml file and add new apt target:

    <target name="process-annotations">
        <echo>Processing annotations</echo>
        <mkdir dir="build/generated-classes"/>
        <apt compile="false" srcdir="${src.src.dir}" factory="your.AnnotationProcessorFactory"
        preprocessdir="build/generated-classes" classpath="${javac.classpath}" includeantruntime="false"/>

What you might want to change is:
factory – is class name of Java 1.5 annotation processor factory (check Oracle guide for annotation processing in 1.5 for details)

Rest should work as is. Annotation processor will output it’s files in build/generated-classes folder in your project root.

Then just run it manually (then you need to make it depend on init,deps-jar) or better on -pre-compile target that is automatically executed by Netbeans just before compiling your source folders (just copy code below to build.xml and use clean&build):

<target name="-pre-compile">
    <antcall target="process-annotations"/>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: