Can I list the resources in a given package?

*爱你&永不变心* 提交于 2019-11-28 00:42:09
SCdF

No, you can't list resources in a package because the JVM simply doesn't know what resources are in what package. See this question.

jcfolsom

Yes. You can use ClassLoader.getResources("");

Or you could use ferret API:
https://www.ohloh.net/p/pureperfect-ferret

This API allows you to scan the class path as well as arbitrary archives and directories using the Visitor pattern.

Daniel Rikowski

The Spring Framework offers a class called PathMatchingResourcePatternResolver. With this class you can give Ant style paths with wildcards and it will find the relevant resources for you (searching through the folders and jars on the classpath).

I do this: - before packaging, ls myResources/*.ext > myResources/list.txt - then just read the file first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!