listing of system resources

H

HK

Hi,

with ClassLoader.getSystemResource() I have access to
specific files on the CLASSPATH, in particular to
files stored in the jar file in which the
application resides.

Question: is there a way to list all resources
in a given subdirectory that is stored in a jar
file.

The idea is to have a bunch of configuration
files which discribe certain services. The application
should figure out itself which services were
shipped with it. I could of course add a
file which lists the available services, but
this would be superfluous if I could
list the resource files.

Harald.
 
B

Ben_

I don't see the goal you're trying to achive, but you can enumerate the
classpath entries to see if it is a file or a directory. If a jar, you can
enumerate the archive with the zip/jar API. If a directory, you can browse
it with File API.
 
M

Mark Thornton

HK said:
Hi,

with ClassLoader.getSystemResource() I have access to
specific files on the CLASSPATH, in particular to
files stored in the jar file in which the
application resides.

Question: is there a way to list all resources
in a given subdirectory that is stored in a jar
file.

The idea is to have a bunch of configuration
files which discribe certain services. The application
should figure out itself which services were
shipped with it. I could of course add a
file which lists the available services, but
this would be superfluous if I could
list the resource files.

Harald.

No you can't. Using a file, which by convention is located in the
META-INF directory, is the correct way to do this. Note that you can
have multiple occurrences of the same file name --- one in each jar and
then use ClassLoader.getResources to obtain a URL for each instance.

Traversing the CLASSPATH yourself does not work for several reasons:
1. Some entries in the classpath may not support directory listing. For
example urls using the http protocol.
2. Resources can be located in places which do not appear in the
classpath. One example of this is where an application has been launched
using the -jar option and contains a Class-Path entry in its Manifest.
3. Custom class loaders can locate resources by other means not visible
to the rest of the application.

Mark Thornton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top