Eclipse Plugin and URLClassLoader [message #491112] |
Tue, 13 October 2009 10:39 |
StefanK Messages: 25 Registered: July 2009 |
Junior Member |
|
|
Hello,
I´m currently working on a eclipse plugin text editor using JFace. There is a content assist, which is accessable via ctrl+space. The content assist should give the user the option to select between various methods. The code so far:
//the path to the .class files
private static final String PATH = "C:/trunk/Parser/A4GLRuntime/bin/standardlibrary/";
public ArrayList<String> getMethodsForContentAssist() {
if (mSizeChanged) {
for (String lTmp : A4LStandardFunctionArrayList.getInstance()) {
Class<?> lClass = getClassForName(lTmp);
for (Method lMethod : lClass.getDeclaredMethods()) {
mList.add(lMethod.toString());
}
}
return mList;
}
The singleton A4LStandardFunctionArrayList contains the classnames, every class needs to be loaded so that the methods can be extracted.
private Class<?> getClassForName(String pName) {
Class<?> lResult = null;
try {
URL[] lUrl = new URL[1];
File lFile = new File(PATH);
lUrl[0] = new URL(lFile.toURI().toURL().toString());
URLClassLoader lLoader = new URLClassLoader(lUrl);
lResult = lLoader.loadClass(pName);
} catch (Exception Ex) {
System.out.println(Ex.toString());
}
return lResult;
}
pName contains the name of the .class file, i.e. "Strings". The class "Strings.class" is available in the bin directory.
If I start the plugin and activate the content assist, the following exception is thrown:
Unhandled event loop exception
java.lang.NoClassDefFoundError: Strings (wrong name: standardlibrary/Strings)
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$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
etc.
This Exception is thrown as soon as the URLClassLoader tries to load the specified class "pName", but I´m absolutely clueless why this is happening.
Thanks for the help.
Best regards
StefanK
[Updated on: Tue, 13 October 2009 10:52] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02682 seconds