How can I use ClassLoader.getResources()
to find recursivly resources from my classpath?
E.g.
finding all resources in the META-INF
"directory":
Imagine something like
getClass().getClassLoader().getResources("META-INF")
Unfortunately, this does only retrieve an URL
to exactly this "directory".
all resources named bla.xml
(recursivly)
getClass().getClassLoader().getResources("bla.xml")
But this returns an empty Enumeration
.
And as a bonus question: How does ClassLoader.getResources()
differ from ClassLoader.getResource()
?
There is no way to recursively search through the classpath. You need to know the Full pathname of a resource to be able to retrieve it in this way. The resource may be in a directory in the file system or in a jar file so it is not as simple as performing a directory listing of "the classpath". You will need to provide the full path of the resource e.g. '/com/mypath/bla.xml'.
For your second question, getResource will return the first resource that matches the given resource name. The order that the class path is searched is given in the javadoc for getResource.