java如何实现getClassLoader()的等效功能。Eclipse插件中的getResources()?
我有一个IJavaProject
,我需要在这个项目的类路径上找到资源,即getClassLoader().getResources()
的等价物(注意:这个调用返回Enumeration<URL>
,而不是单个URL
)
如何从Eclipse捆绑包/插件中检查Java项目的类路径,例如查找包含log4j.xml
的所有类路径条目
你可以在下面搜索框中键入要查询的问题!
我有一个IJavaProject
,我需要在这个项目的类路径上找到资源,即getClassLoader().getResources()
的等价物(注意:这个调用返回Enumeration<URL>
,而不是单个URL
)
如何从Eclipse捆绑包/插件中检查Java项目的类路径,例如查找包含log4j.xml
的所有类路径条目
# 1 楼答案
使用
getPackageFragmentRoots()
获取类路径中的等价项。对于每个根,您可以调用getNonJavaResources()
来获取该根下的非java内容,并且可以递归调用getChildren()
来获取子级(以java层次结构的方式)。最终,这些间接遍历的子对象将是java源文件,您可以通过向它们发送getUnderlyingResource()
方法来确认这些源文件下面是一些代码: