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]
# 1

Subclass URLClassLoader, and have it scan specified folders for jar files. When it finds one, obtain a URL for it, and call addUrl(url)

georgemca at 2007-7-28 15:40:59 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

malcolmmca at 2007-7-28 15:40:59 > top of Java-index,Java Essentials,Java Programming...
# 3

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.

BigDaddyLoveHandlesa at 2007-7-28 15:40:59 > top of Java-index,Java Essentials,Java Programming...
# 4

Java 6 accepts directories on the classpath.

dwga at 2007-7-28 15:40:59 > top of Java-index,Java Essentials,Java Programming...