tags:

views:

49

answers:

3

In Java, how can I create a ClassLoader which will use a particular classpath (probably just a single jar file)?

+3  A: 

You create a URLClassLoader object.

bmargulies
A: 

Here is a good article on class loading:

http://onjava.com/pub/a/onjava/2005/01/26/classloading.html

richs
A: 

Indeed, create a URLClassLoader as pointed out by @bmargulies. It's pretty easy to use, just pass an array of URLs into the constructor.

Maybe also check this thread and, in particular, this post for some tips on how to use Java (hierarchical) ClassLoaders. I don't know what you want to do exactly but you may find it useful.

Pascal Thivent