Skip to main content

Using of reflection:strange beheviour

1 reply [Last post]
giuseppe83
Offline
Joined: 2005-08-31
Points: 0

I'm trying to dinamical load classes that have dependecies from some jar file. I have writed this example.

public class prova {

public prova()throws Exception{

URLClassLoader cl;
File f1=new File("C:/IRApplication/lib/jdeal/jdeal.jar");
File f2=new File("C:/IRApplication/IR");
File f10=new File("C:/IRApplication/extensions/algorithms/DCGA");

URL url1=f1.toURL();
URL url2=f2.toURL();
URL url10=f10.toURL();

URL[] u=new URL[] {url2,url1,url10};
cl = new URLClassLoader(u,this.getClass().getClassLoader());

Class c=Class.forName("it.unisannio.rcost.cise.dcga.IRDeterministicCrowding",true,cl);
System.out.println("OK");
}
/**
* @param args
*/
public static void main(String[] args) throws Exception{
prova p=new prova();

}

}

An exception is throwed.

Exception in thread "main" java.lang.NoClassDefFoundError: pt/laseeb/jdeal/ChromosomeEvaluator
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at prova.(prova.java:21)
at prova.main(prova.java:28)

Could someone help me to understand why?? There are lots of days that I try to understand!!!

Message was edited by: giuseppe83

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
giuseppe83
Offline
Joined: 2005-08-31
Points: 0

SOLVED