Issue 14755 - Rhino runtime does not support loading of Java classes packaged with script
Summary: Rhino runtime does not support loading of Java classes packaged with script
Status: CLOSED FIXED
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: OOo 1.1 Beta2
Hardware: All All
: P2 Trivial (vote)
Target Milestone: OOo 2.0
Assignee: tomaisoc
QA Contact: issues@framework
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-22 17:18 UTC by tomaisoc
Modified: 2003-06-13 18:38 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description tomaisoc 2003-05-22 17:18:25 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().
Comment 1 noel.power 2003-06-03 10:42:11 UTC
Reassign to Tom
Comment 2 tomaisoc 2003-06-04 11:03:03 UTC
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.
Comment 3 robert.kinsella 2003-06-13 18:38:40 UTC
thanks Tom, 
tested with sample parcel, supplied by Tom - verified fixed SF 0.3 rc4
closing issue