查找运行时Java可用的所有类 [英] Find all classes availible at runtime java

查看:176
本文介绍了查找运行时Java可用的所有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找Java运行时可用的所有类的名称,并且在Guava中通过反射使用了如下代码,从而取得了一些成功:

ClassPath classPath = ClassPath.from(ClassLoader.getSystemClassLoader());
contextClasses = classPath.getAllClasses();

这似乎在某种程度上可以使我获得大约2500个类名,但是并没有找到所有的类名,特别是我确实需要了解的类java.lang,java.util等. /p>

我应该为此使用其他类加载器吗?我也尝试过

Thread.currentThread().getContextClassLoader()

任何指针将不胜感激.谢谢

Ewen

有关解决方案的更多详细信息.

我使用了来自此帖子的更多信息:解决方案

对于1.5版JVM,您可以使用How can I list all classes loaded in a specific class loader to actually implement the solution suggested in the answer. This seams to get all of the standard java libraries (some 500 ish) but not the ones I go in my method previously. I could combine with the previous to get everything I need.

Thanks to everyone for their help.

解决方案

For a post 1.5 JVM, you can use http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/Instrumentation.html#getAllLoadedClasses().

这篇关于查找运行时Java可用的所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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