Dynamic loading of jar files using custom classLoader [message #514844] |
Tue, 16 February 2010 20:26 |
Sönke Holsten Messages: 6 Registered: February 2010 |
Junior Member |
|
|
I've been searching for possibilities to dynamically load jar files for quite a while and came across a custom classLoader I like (available here). I downloaded the resources from that site (JarClassLoader.java, JarResources.java and MultiClassLoader.java) and put them to use in a small test project which worked out fine. However I want to use the JarClassLoader inside an Eclipse plug-in and for some reason I haven't been able to simply reuse the code from the test project for that purpose. The code I'm using in both the java test project and in the plug-in project is the following:
public static void run() {
JarClassLoader jarLoader = new JarClassLoader ("C:\\somepath\\testjar.jar");
try {
Class c = jarLoader.loadClass ("TestClass", true);
Object o = c.newInstance();
if (o instanceof TestClass) {
System.out.println("works...");
TestClass tc = (TestClass) o;
String test = tc.doSomething();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
In the normal java project I have a main method which just calls the method run() and does nothing else. In the Eclipse plug-in project I have an action that when executed also just calls the method run() and nothing else. The problem is that in the Eclipse plug-in the check whether the created object is an instance of the class I desire fails, that is "works..." is never even printed. Although in debug mode it says that the object o is actually an instance of the class TestClass.
Can anyone point me to what I might be doing wrong?
Thank you for your help!
[Updated on: Wed, 17 February 2010 11:07] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03130 seconds