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

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

问题描述

是否有命令行工具,最好在 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?

我在谷歌上搜索了一段时间,但没有运气.:(

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

推荐答案

如果我错了,请纠正我,但我认为,编译器会从类中剥离注释,除非您使用注释 @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:

注释实用程序

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

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