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. :(
The javap command disassembles one or more class files. Its output depends on the options used. If no options are used, javap prints out the package, protected, and public fields and methods of the classes passed to it.
A simple way to see what String literals are used in a ". class" file is to use the javap utility in your JDK installation to dump the file using the "-v" option. Then grep for text that looks like <String "..."> where ... is the String you are looking for.
The isAnnotation() method is used to check whether a class object is an annotation. The isAnnotation() method has no parameters and returns a boolean value. If the return value is true , then the class object is an annotation. If the return value is false , then the class object is not an annotation.
Using the -verbose or -v flag with javap version 1.7 or later will show the retained annotations.
Example:
javap -p -v ./services/target/windup-web-services/WEB-INF/classes/org/jboss/windup/web/services/model/RegisteredApplication.class #50 = Utf8 Ljavax/persistence/Column; #64 = Utf8 Lorg/jboss/windup/web/services/validators/NotBlankConstraint; #67 = Utf8 Ljavax/validation/constraints/Size; ... private java.lang.String title; descriptor: Ljava/lang/String; flags: ACC_PRIVATE RuntimeVisibleAnnotations: 0: #50(#62=I#63) 1: #64(#65=s#66) 2: #67(#68=I#69,#70=I#63,#65=s#71
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With