Subj : Linking in a JS library To : netscape.public.mozilla.jseng From : ongewenste_email Date : Tue Oct 19 2004 03:04 am Hi all, I'm trying to link in a javascript library using Rhino. I have a main script A, which needs to import library B. What I've done is create a java Import class, which looks something like this : public class JSImport { // the library private static String m_Script = "function b(){Packages.java.lang.System.out.println("Hello B");}"; // do the import public static void doImport() throws Exception{ Context ctx = Context.enter(); ctx.setCompileFunctionsWithDynamicScope(true); ScriptableObject scope = new ImporterTopLevel(ctx); Script script = ctx.compileString(ScriptCompileTest.lib, "lib", 0,null); script.exec(ctx, scope); ctx.exit(); } } Now from some script A I import B : // invoke the import Packages.tools.JSImport.doImport(); // run the code. a(); function a(){ Packages.java.lang.System.out.println("Hello A"); } b(); The problem is that the calling thread's scope doesn't see the library, which makes sense since I use a threadLocal scope in the calling script: ScriptableObject scope = ctx.initStandardObjects(null, false); Scriptable threadScope = new ImporterTopLevel(ctx); threadScope.setPrototype(scope); m_CompiledScript.exec(ctx, threadScope); If I make the threadScope object accessible to JSImport , it works fine, but I don't like that. So my question is, is there a way I can get to the active scope object using Rhino's API, or is there a different way altogether to achieve this import functionality in javascript ? cheers, Edwin. .