如何通过命令行查看java classfile的注释? [英] How to view annotation of java classfile via command line?

查看:141
本文介绍了如何通过命令行查看java classfile的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个命令行工具,最好是在JDK中,要么在类文件中打印所有注释,要么将特定注释作为参数进行打印?

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?

如果是这样的话,是否有一个等效的命令可以在一个jar文件上运行,包含在一个特定的类中?

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

我用Google搜索了一段时间并且没有运气。 :(

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

推荐答案

如果我错了,请纠正我,但我想,编译器会从类中删除注释,除非你在Annotations本身上使用Annotation @Retention(RetentionPolicy.RUNTIME),信息不会保存在类文件中。
如果注释保存在类文件中,你可以使用javap(jdk的一部分)来看那些:

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

更新:这似乎需要JDK7,JDK6的javap不会打印注释,但您可以使用华盛顿大学网站上的以下工具来提取注释信息:

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

这篇关于如何通过命令行查看java classfile的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆