Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Classes visibility between different plug-in projects
Classes visibility between different plug-in projects [message #490725] Fri, 09 October 2009 20:43 Go to next message
Milton  is currently offline Milton Friend
Messages: 10
Registered: October 2009
Junior Member
I am developing a RCP application that provides the ability to execute scripts using Rhino JavaScript engine. Rhino provides a function called importClass() that allows to make a java class visible from the script and I need to use this function to include some classes in my plug-in project.

This is what I am doing:

1. I have Rhino in a separate plug-in project. From this project I export all the packages in the manifest file.

2. From my plug-in project I add a dependency to Rhino's plug-in bundle so I can use all classes in there.

3. From my plug-in I access Rhino classes to execute the scripts. When importClass() is called Rhino checks for a valid java class by calling the java function Class.forName() which is throwing a ClassNotFoundException because it is not visible from Rhino's project (that's my best guess)

I ran this code from my plug-in to break down the problem:

try
{
System.out.println(Class.forName("com.avionyx.atest.scripting.asl.GPIB.GPIBConnection ").getName());
System.out.println(org.mozilla.javascript.Kit.classOrNull("com.avionyx.atest.scripting.asl.GPIB.GPIBConnection ").getName());
}
catch (Exception ex)
{
ex.printStackTrace();
}

The result is that the first line runs perfectly and the call to classOrNull returns null.

The code of the function classOrNull is on Rhinos project and basically does the same above; calls Class.forName and returns null if the class is not found. The code is:

public static Class classOrNull(String className)
{
try {
return Class.forName(className);
} catch (ClassNotFoundException ex) {
} catch (SecurityException ex) {
} catch (LinkageError ex) {
} catch (IllegalArgumentException e) {
// Can be thrown if name has characters that a class name
// can not contain
}
return null;
}

This means that Class.forName returns the class if called within the project where the class is defined, but it fails if called from the other project.

Is there any fix for this?

Thank you,
Milton.
Re: Classes visibility between different plug-in projects [message #490961 is a reply to message #490725] Mon, 12 October 2009 15:20 Go to previous messageGo to next message
Thomas SZADEL is currently offline Thomas SZADELFriend
Messages: 36
Registered: July 2009
Member
Hi Milton,

It seems to be a class-path problem ("are you kiding?" Very Happy )...
Your main plugin has visibility to you rhino plugin. That's to say (roughly) the class-path of your rhino plugin is added to the class-path of (A).

When you call Class.forName(...) inside the Rhino plugin, you use the class-path of your Rhino plugin and not the one of your main plugin.
What you want to do is to reverse the dependency and to allow the rhino plugin to access the classpath of your main plugin.

So, let's try the Buddy class loading to do such a thing:

In your rhino plugin, add (in the MANIFEST.MF):
Eclipse-BuddyPolicy: registered


In your main plugin(in the MANIFEST.MF):
Eclipse-RegisterBuddy: <rhino plugin id>


Let's have a look at that wiki page: http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhan cements


Tom
icon14.gif  Re: Classes visibility between different plug-in projects [message #491025 is a reply to message #490961] Mon, 12 October 2009 20:38 Go to previous message
Milton  is currently offline Milton Friend
Messages: 10
Registered: October 2009
Junior Member
Thanks a lot Tom, that made the job.

I had a firefox tab with all the MANIFEST file options and I never took the time to read all of them...

Milton.
Previous Topic:derby nature
Next Topic:Why works ElementListSelectionDialog only at complete started workbench?
Goto Forum:
  


Current Time: Sat Apr 20 01:47:47 GMT 2024

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

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

Back to the top