Java:循环类路径中的所有类 [英] Java : loop on all the classes in the classpath

查看:115
本文介绍了Java:循环类路径中的所有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法迭代类路径中的所有类?

Is there a way to iterate over all the classes in the classpath ?

我想对某些实现某个接口的类进行一些反思性检查,但我想完全动态地完成它,而不需要检查哪些类,只需浏览类路径。

I want to make some reflective checks on some classes implementing a certain interface, but I want to do it completely dynamically, without any input on which classes to check, just browsing the classpath.

推荐答案

思考库有助于解决这个问题。正如其他人所说的那样,在所有类加载情况下都不是完全可能的,但如果您拥有的只是罐子和文件,那么这将是可靠的。

The Reflections library helps deal with this problem. As others have stated, it isn't fully possible in all class loading situations, but if all you have are jars and files, this will do it reliably.

这篇关于Java:循环类路径中的所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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