views:

274

answers:

2

The typically method to reference a file contained with a JAR file is to use ClassLoader.getResource. Is there a way to get the contents of a directory within a JAR files (similar to java.io.File.listFiles())? Note that the JAR file is within the classpath and its filename might not be known during runtime.

Basically I have a bunch of non-.class resource files within a directory. At runtime I need to load each resource file contained within a known directory.

A: 

There is a system property called java.class.path, parse the path to your jar and then use JarURLConnection class to do what you want.

Murali VP
+2  A: 

See "List files inside a JAR".

erickson