Dynamically loading jar files

Hi

In my application I need to dynamically create objects of types specified by string which is passed as parameter. I am able to do this if the class is inside the same jar. But I need to load the class from any jar name specified. How do i go about doing this? Is there a way to dynamically loading jar files?

[325 byte] By [dan_aravinda] at [2007-10-3 4:33:42]
# 1

It's easy. You use [url http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html]URLClassLoader[/url]:String jarPath = ...;

String className = ...;

URLClassLoader ucl = new URLClassLoader(new URL[] { new File(jarPath).toURL() });

Class cls = Class.forName(className, true, ucl);

...

Regards

jfbrierea at 2007-7-14 22:37:19 > top of Java-index,Core,Core APIs...