Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Problem in ClassLoading(ClassLoading works fine if i run as java application but same code in RCP gives a circularity error)
Problem in ClassLoading [message #1053019] Thu, 02 May 2013 04:48
Prasanth Jonna Vamsi is currently offline Prasanth Jonna VamsiFriend
Messages: 10
Registered: January 2013
Junior Member
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.
Previous Topic:Unhandled event loop exception
Next Topic:RCP+JNLP x64: bundle org.eclipse.core.runtime not resolved
Goto Forum:
  


Current Time: Tue Nov 25 02:13:44 GMT 2014

Powered by FUDForum. Page generated in 0.01794 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software