Apache OpenOffice (AOO) Bugzilla – Issue 14755
Rhino runtime does not support loading of Java classes packaged with script
Last modified: 2003-06-13 18:38:40 UTC
If you write a Javascript script to be run by the ScriptRuntimeForRhino and you ship some Java classes or jar files with that script that you want it to be able to load, the script currently cannot load those classes. The ScriptRuntimeForRhino is not currently setting up a custom ClassLoader for the script execution. It needs to do this. The Rhino integration in the Bean Scripting Framework from Apache sets up a ClassLoader and passes it as the last so we should be able to do the same and pass it as the last argument to our call to Context.evaluateReader().
Reassign to Tom
My previous comment was incorrect, it is the xml-batik project from Apache (http://xml.apache.org/batik/) which passes in its own ClassLoader when calling evaulateReader(). This feature in Rhino is designed for setting up Authorization for JavaScript scripts ie. what classes they are allowed to load. I searched through the Rhino mailing list and it seems that the recommended way to set up a ClassLoader to be used when interpreting scripts is to call Thread.currentThread().setContextClassLoader() before setting up the Context and calling evaluateReader(). I tried doing this, but it didn't work, apparently due to a bug related to class loading in Rhino 1.5R4 (query http://bugzilla.mozilla.org for Product Rhino and Comment containing ClassLoader). I then tried using Rhino 1.5R4.1 and a sample JavaScript script was able to load classes from my parcel directory successfully. Using 1.5R4.1 did not adversely effect any other functionality (eg. the Rhino Debugger). So the fix is to call Thread.currentThread().setContextClassLoader() and to use Rhino 1.5R4.1. There should not be any clashes when loading classes as each script invocation in the ScriptRuntimeForJavaScript should be happening in a new thread created by UNO.
thanks Tom, tested with sample parcel, supplied by Tom - verified fixed SF 0.3 rc4 closing issue