If I have a collection of resource files in a directory on my classpath, I can enumerate them using ClassLoader.getResources(location)
.
For example if I have /mydir/myresource.properties
on the classpath, I can call the classloader's getResources("mydir")
and get an enumeration of URLs containing myresource.properties
.
When I pack up the exact same resources into a .jar, I don't get anything in the enumeration of URLs when I make the call. I've only replaced the folder structure with a jar containing those folders (it's a webapp, so the jar is going into /WEB-INF/lib
). I've also got a number of other calls using getResourceAsStream(location)
to get other resources individually by name and they're all working fine.
What's different about enumerating resources when the resources are in a .jar?
Update - I've reproduced (ish) the behaviour outside the container. The following snippet results in the dirProperties
object having keys set to the resource names in the package, but if the package is in a .jar throws a NullPointerException during the Properties.load(InputStream) method.
Properties dirProperties = new Properties();
dirProperties.load(this.getClass().getClassLoader().getResourceAsStream(location));
The same code on the container (Tomcat 5.5) throws no exception but produces an empty Properties object when the files are in a .jar.