以编程方式检查 .class 文件是否扩展特定类
我有一个问题,我已经尝试解决好几个小时了。在 Eclipse 插件中,我有一个 ArrayList,其中包含一些 java .class 文件的完整路径(作为字符串)。我想做的是检查列表中包含的类是否扩展了特定的类。我考虑过解析该文件,查找“extends”之后的内容,但是我们谈论的是 .class 文件而不是 .java 文件。还有其他想法吗?
谢谢!
I have a problem I've been trying to solve for quite some hours. In an Eclipse plugin, I have an ArrayList that contains the full paths (as strings) of some java .class files. What I'd like to do is check if the classes that are included in the list extend a particular class. I thought about parsing the file, looking for what is after "extends," however we are talking about a .class file and not of a .java file. Any other ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 URLClassLoader 加载文件(问题:您需要知道正确的父文件夹和 Package + ClassName)并使用普通的 java.lang.Class 方法进行检查。
Use an URLClassLoader to load the file (Problem: You would need to know the right parent folder and Package + ClassName) and use the normal java.lang.Class methods to check.
您正在寻找的工具是 asm。 (或者 bcel,但现在 asm 更流行。)
The tool you're looking for is asm. (Or bcel, but asm is more popular these days.)