ClassLoader
Hi..
i'm trying to load class files from provided jar file.i'm creating ClassLoader onject and calling defineClass.. method for every class in jar.my problem is that,i'msuccess fully able to load some classes while some classes throws java.lang.ClassFormaError. can anybody suggest me a fine solution.i've included my code snippet which looks after this loading unction...
private Class loadClass(final JarEntry jarentry) {
try {
Class loadedclass = new ClassLoader() {
public Class findClass(String name) {
try {
InputStream is = jarfile.getInputStream(jarentry);
int available = is.available();
byte data[] = new byte[available];
is.read(data);
name = parseClassName(name);
try {
return defineClass(name, data, 0, data.length);
}catch(ClassFormatError err) {
System.out.println(err+"class not loaded :"+name );
return null;
}
}catch(IOException ex) {
return null;
}
}
}.loadClass(jarentry.getName());//classname);
return loadedclass;
}catch(Exception e) {
e.printStackTrace();
return null;
}
}
Thanks... <center></center><div align="left"></div id="left"><center></center>
|