Problem in ClassLoading [message #1053019] |
Thu, 02 May 2013 00:48 |
Eclipse User |
|
|
|
I have a java application which loads the class data from given path and then defines the class.
public class tempClassLoader extends ClassLoader {
void samp1() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Class c = findClass("");
}
@Override
protected Class<?> findClass(final String name)
throws ClassNotFoundException {
byte[] classBytes = null;
classBytes = loadClassData("C:/PRASANTH/Infineon/Baseline/appP/collayoutalgo/vamsi"
+ ".class");
Class c = null;
if (classBytes != null) {
c = defineClass(null, classBytes, 0, classBytes.length);
}
resolveClass(c);
return c;
}
public byte[] loadClassData(String name) throws ClassNotFoundException {
File classFile = new File(name);
byte[] buf = null;
try {
InputStream in = new FileInputStream(classFile);
buf = loadBytesFromStream(in, (int) classFile.length());
in.close();
} catch (Exception e) {
throw new ClassNotFoundException();
}
return buf;
}
private byte[] loadBytesFromStream(InputStream in, int length)
throws IOException {
byte[] buf = new byte[length];
int nRead, count = 0;
while ((length > 0) && ((nRead = in.read(buf, count, length)) != -1)) {
count += nRead;
length -= nRead;
}
return buf;
}
public static void main(String[] args) throws InstantiationException,
IllegalAccessException {
tempClassLoader obj = new tempClassLoader();
try {
obj.samp1();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
I created a RCP application and called samp1() from createPartControl() . It lands into circularity error . I think there must a different way to define class in RCP. CAn anyone let me know the correct way to use defineclass() in RCP.
|
|
|
Powered by
FUDForum. Page generated in 0.01981 seconds