posted 19 years ago
You could create your own URLClassLoader that includes only the JAR you're interested in, but this isn't really necessary if the JAR is already on the CLASSPATH.
Trying to modify the classpath at runtime using setProperty won't work, the property appears to be read-only and the change is ignored.
The problem you'll encounter is that you can only use reflection on classes loaded by a ClassLoader, and you can only load classes by their fully qualified names. If your aim is to find all the classes in a JAR file, load them and output information using reflection, first you need to find the fully qualified names of all classes in the JAR. There isn't a direct way to do this.
You'll probably have to use the java.util.zip functionality to find all files in the JAR, filter the ZipEntries for .class files, convert the path and name into a fully qualified class name, then get a reference to the Class through a ClassLoader. Sounds like a lot of work but it shouldn't be too hard.
Tell us how you go?
Dave