Using the ClassLoader method to retrieve all resources under classes as Input Streams

半城伤御伤魂 提交于 2019-12-01 22:13:28

You can do that with some tricks :)

Get the resource as URL, extract the protocol :

  • file protocol - get the URL path and you have a folder, scan for files.
  • jar/zip protocol - extract the jar/zip path and use JarFile to browse the files and extract everything under your path/package.

As far as I am aware, there is no such ability, since the classloader only attempts to load things it is asked for. It doesn't pre-fetch all items on the classpath, or treat them as a directory structure.

The way I would solve the problem is create a directory listing in a text file of all relevant resources at build time and include that in the war, and then walk it through that way.

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