How do I find resources in a .jar on the classpath?
- by Brabster
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?