views:

41

answers:

1

Hi,

Is there a command line tool, preferrably in the JDK, that either prints all annotations in a classfile or takes a specific annotation as argument to print?

If so, is there an equivalent command that can be run on a jar file for a specific class contained within?

I've googled this for a while and had no luck. :(

Thanks, Jack

+1  A: 

Correct me if im wrong, but I thought, that annotations are stripped from the classes by the compiler, unless you use the Annotation @Retention(RetentionPolicy.RUNTIME) on the Annotations itself, the information will not be preserved in the class file. If the annotations are preserved in the classfile, you can use javap (part of the jdk) to see those:

javap my.package.MyClass

Update: This seems to need JDK7, JDK6's javap doesnt print the annotations, but you can use the following tools from the University of Washington's website to extract the Annotation Information:

Annotation-utilities

smeg4brains
Thanks for this. I was playing with the tools in the JDK/bin directory and found this one. This doesn't seem to display the annotation though but I can see it through a text editor: "RuntimeVisibleAnnotations^A^@!L<package removed>/VersionID;^A^@^Evalue^A^@^P$Revision: 1.5 $"
Jack Griffith
I should add this annotation has @Retention(RetentionPolicy.RUNTIME) as you specified.
Jack Griffith