writing classloader to load jar files
Hi,
I have to load all the jar files residing in a folder .
I don't know the name and the no. of jars in the folder , so cannot set them in classpath by specifying java -classpath .;abc.jar;xyz.jar myapp .
so how to achieve that .
thanks in advance
regards,
yogvinder
[312 byte] By [
javejesta] at [2007-11-27 10:15:41]

Subclass URLClassLoader, and have it scan specified folders for jar files. When it finds one, obtain a URL for it, and call addUrl(url)
You don't need to subclass it.
Incidentallty it's slightly dubious practice in some cases by you can give java access to all jars in a directory by using -Djava.ext.dirs=path.
I don't think you *have*to* subclass URLClassloader -- what method must be overridden? Just search that directory and discover the names of the jars, fluff that into a URL[], construct a URLClassloader, and off you go.