Classes visibility between different plug-in projects [message #490725] |
Fri, 09 October 2009 16:43  |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03062 seconds