cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ssudan
Level 2

Load Classes from external jar

Hi,

I want to load some classes from an external jar file. The code goes as

URL[] url = new URL[]{new URL("jar:file:d:\\Install\\hello.jar!/")};
URLClassLoader loader1 = new URLClassLoader(url);
Class cls1 = Class.forName("Hello",true,loader1);
Method meth[] = cls1.getMethods();
for(int i=0;i {

if(meth.getName().equals("add"))
{

meth.invoke(cls1.newInstance(),new Object[]{});
}
}

But this throws an ClassNotFoundException. The output is

java.lang.ClassNotFoundException: Hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at com.installshield.test.event.dialog.swing.PanelDestination.enteredDes
tination(PanelDestination.java:263)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.installshield.event.ActionSequenceEngine$ActionTask.invokeJavaMet
hod(Unknown Source)
at com.installshield.event.ActionSequenceEngine$ActionTask.executeAction
(Unknown Source)
at com.installshield.event.ActionSequenceEngine$ActionTask.run(Unknown S
ource)
at com.installshield.event.ThreadPool.run(Unknown Source)
at java.lang.Thread.run(Thread.java:534)


Could anyone help me on resolving this.

Thanks in advance
Sudan
Labels (1)
0 Kudos
(1) Reply
Eyal_Goren
Level 6

Hi,

If you use a custom bean, you need to add in the build method a call for the putArchive, and give the jar as parameter (Assuming you need the jar that exist on your build environment).

Eyal
0 Kudos