How do I find resources in a .jar on the classpath?

Posted by Brabster on Stack Overflow See other posts from Stack Overflow or by Brabster
Published on 2010-03-31T14:29:09Z Indexed on 2010/03/31 14:33 UTC
Read the original article Hit count: 230

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about classpath