This discussion is archived
6 Replies Latest reply: Feb 8, 2009 11:28 PM by 791266 RSS

Is annotation processing the same for Java 5 and Java 6?

843793 Newbie
Currently Being Moderated
I've been trying to use a package of annotations and processors that was evidently originally designed to be used with "apt" and Java 5. When I try to use this stuff with Java 6 I was assuming that, since the Java 6 javac handles annotations, I could just use javac instead of apt - but it doesn't work; the annotation processors don't appear to be getting executed. It looks like I have to use apt for the Java 6 build after all.

The question is, did the annotation mechanism change significantly between 5 and 6 that would account for this? Is there a way to adapt an annotation package (i.e. annotation classes and processors) that works with 5 so that it will work with 6 using javac instead of apt (or alternatively, is there a way to tell javac to process the older annotations in the same way that apt would)?
  • 1. Re: Is annotation processing the same for Java 5 and Java 6?
    mlk Newbie
    Currently Being Moderated
    did the annotation mechanism change significantly between 5 and 6 that would account for this?
    I'm fairly sure the API for 5 (JSR 175) is quite a bit different to 6 (JSR 269).
    Java 5 was all in the sun name space (something one should never use according to Sun), in Java 6 parts of it get rejigged and moved into javax.

    Edited by: mlk on 21-Nov-2008 16:28
  • 2. Re: Is annotation processing the same for Java 5 and Java 6?
    843793 Newbie
    Currently Being Moderated
    PeteFord wrote:
    I've been trying to use a package of annotations and processors that was evidently originally designed to be used with "apt" and Java 5. When I try to use this stuff with Java 6 I was assuming that, since the Java 6 javac handles annotations, I could just use javac instead of apt - but it doesn't work; the annotation processors don't appear to be getting executed. It looks like I have to use apt for the Java 6 build after all.

    The question is, did the annotation mechanism change significantly between 5 and 6 that would account for this? Is there a way to adapt an annotation package (i.e. annotation classes and processors) that works with 5 so that it will work with 6 using javac instead of apt (or alternatively, is there a way to tell javac to process the older annotations in the same way that apt would)?
    If you have apt annotation processors, you can use the apt command in JDK 6.

    However, the javac in JDK 6 support standardized JSR 269 annotation processing; see the javax.annotation.processing package. JSR 269 annotation processing is significantly redesigned and improved based on experiences with apt.

    It would be "a small matter of programming" to port an apt annotation processor to JSR 269.

    Using apt in JDK 6, you can also run both apt and javac processors from a single command line invocation.
  • 3. Re: Is annotation processing the same for Java 5 and Java 6?
    843793 Newbie
    Currently Being Moderated
    The apt annotation processors in question are supplied as part of a third-party package, so I can't modify them (well actually we have the sources so technically we could, but there's little point). No matter; the point is that the package was intended to be used with apt and so I can set up my build to do it that way - it should work just fine.

    The responses here explain what I'm seeing and answer my question - thanks, all.
  • 4. Re: Is annotation processing the same for Java 5 and Java 6?
    843793 Newbie
    Currently Being Moderated
    I was running into the same issue, glad you asked it Pete.

    Joseph,
    [hypnotize someone blog|http://theartofcoverthypnosis.com/]
  • 5. Re: Is annotation processing the same for Java 5 and Java 6?
    608410 Newbie
    Currently Being Moderated
    abuse reported
  • 6. Re: Is annotation processing the same for Java 5 and Java 6?
    791266 Explorer
    Currently Being Moderated
    I blocked the spam.

    Kaj