Skip to main content



      Home
Home » Eclipse Projects » JFace » Eclipse Plugin and URLClassLoader
Eclipse Plugin and URLClassLoader [message #491112] Tue, 13 October 2009 06:39 Go to next message
Eclipse UserFriend
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 06:52] by Moderator

Re: Eclipse Plugin and URLClassLoader [message #491117 is a reply to message #491112] Tue, 13 October 2009 07:33 Go to previous message
Eclipse UserFriend
Update:

we created a new 4GL for our project, this 4GL is parsed to java code via generator. The created "test".java and "test".class can be loaded by the code posted above without any problems. But if I try to load the .class files that are created by eclipse, the problem descibed above occures.

Now I´m much more clueless than before Confused

Best Regards
StefanK
Previous Topic:Disable Context Menu in the TextCellEditor
Next Topic:blockOnOpen = false for Wizards
Goto Forum:
  


Current Time: Wed Jul 23 03:06:21 EDT 2025

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

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

Back to the top