Dynamic classpath
1 posts in topic
Flat View  Flat View

Posted By:   Diego_Munguia
Posted On:   Wednesday, March 6, 2002 07:15 AM

My application needs to add a new path to the its current classpath, to do something like this:

... add a.b.c.MyClass to the current classpath ...

Class clazz = Class.forName("a.b.c.MyClass");

I already tried setting the 'classpath' property via the System.setProperty() method and it doesn't seem to work


Re: Dynamic classpath

Posted By:   Ward_Harold  
Posted On:   Sunday, March 10, 2002 05:53 PM

Setting classpath at runtime doesn't work because it has already been used to create the App ClassLoader. The easiest thing to do is turn the current classpath into an array of URLs, add a URL for the new path to the end of the array, and create a new URLClassLoader with the URL array you just set up. Now you can use the new ClassLoader to load classes from the newly extended classpath. Make sure to link the new ClassLoader into the existing ClassLoader chain.
About | Sitemap | Contact