How do I add javax.annotation.Generated to Java SE 5?
Asked Answered
M

3

6

I'm working on a project that has to run on Java SE 5 and Java SE 6. I recently started using a tool that adds @Generated annotations to generated code, and I want to keep those annotations. It looks like javax.annotation.Generated is in Java 5 EE and Java 6 SE and later, but is not in the Java 5 SE API.

What's the best way to include javax.annotation.Generated when I send it to the customer, so it will run on both Java SE 5 and Java SE 6 without any problems? Do I just need to include an extra jarfile? If so, which one does @Generated live in?

Mcintyre answered 22/2, 2012 at 22:11 Comment(0)
E
11

You can get javax.annotation.Generated, along with various other classes from that package, from the Maven central repo at this location. You can just download the JARs, you don't need to use Maven to get them.

Answer courtesy of GrepCode.

Equilibrate answered 22/2, 2012 at 22:22 Comment(2)
Thanks to @skaffman. For a Gradle build the dependency should be compile 'org.glassfish:javax.annotation:10.0-b28' then.Tammeratammi
also available with compile 'javax.annotation:jsr250-api:1.0'Alloplasm
G
5

According to javax.annotation.Generated javadoc, its retention is Source, so the annotation won't be compiled to your classes (and result classes with and without this annotation are the same). So your customers never need any jar file containing this annotation, as long as you distribute compiled classes.

Gratification answered 22/2, 2012 at 22:27 Comment(1)
Thanks for the extra info; it's good to know. I neglected to mention it in the question, but we do also give this customer source releases.Mcintyre
G
1

You can just comment them, they are retained only on the source level.

Goto answered 22/2, 2012 at 22:28 Comment(3)
Certainly a valid solution if I only had to generate the code once and never again, but I'd also be concerned about any headaches this might cause future maintainers who don't realize they just need to recomment the annotations after regenerating the code.Mcintyre
If you are using eclipse you can add a builder that removes or comments them out using sed for example. Or a build script would work equally well.Goto
True, but still more effort than just adding the jarfile. Thanks for the "outside-the-box" solution though. :)Mcintyre

© 2022 - 2024 — McMap. All rights reserved.