views:

317

answers:

2

Lets assume my classes are loaded from a compressed .war file or loaded elsewhere, how can I discover all the resources in a given package? Enumerating files will not really work, since this is a war file. Most likely this will involve using the current classloader?

Is there a library out there that does something like that? Googling revealed only some hacks with listing files.

+2  A: 

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.

SCdF
A: 

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).

DerHeiligste