Subj : RE: Java to Javascript using Rhino To : netscape.public.mozilla.jseng From : Aniruddha Thakur Date : Thu Sep 22 2005 10:41 am This is a multi-part message in MIME format. ------_=_NextPart_001_01C5BF94.7EC0BEE2 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Hi All, Update:=20 I was able to run the following from Java using shell.Main in a single-threaded environment. I get errors in multi-threaded evironment. % > java org.mozilla.javascript.tools.shell.Main scripts/helloworld.js anil=20 Hello World from anil=20 % > Here is Java--To--JSscript a class: javaToJS.java that calls tools.shell.Main.main. This part works fine in single threaded environment. Unfortunately, the second part below needs a few modifications to the script itself as i do not know how to pass any arguments (so, i hard coded in the script to test). package scripts; =09 =20 import java.io.FileReader;=20 import org.mozilla.javascript.Context;=20 import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.tools.shell.Main; =09 public class javaToJS { public static void main(String[] args) { Context context =3D Context.enter();=20 ScriptableObject scope =3D context.initStandardObjects(); =20 try { // Part#1: Using tools.shell.Main.main String[] params =3D { "scripts/helloworld.js", "anil" };=20 Main.main(params); // or Main.main(args)=20 =20 // Part#2: Using context and need this for Multi-threaded env to retrieve output FileReader fileReader =3D new FileReader("scripts/helloworld.js"); Object result =3D context.evaluateReader(scope, fileReader, "scripts/helloworld.js", 1, null);=20 System.out.println(Context.toString(result)); System.out.println("---javaToJS DONE----"); } catch (Throwable thr) { thr.printStackTrace(); } finally { Context.exit(); } } } =09 % > javac scripts/javaToJS=20 % > java scripts/javaToJS=20 Hello World from anil << from Part#1=20 % > java scripts/javaToJS << Using Part#2 (recompiled and modified the script)=20 org.mozilla.javascript.EcmaError: ReferenceError: "print" is not defined. (scripts/helloworld.js#1) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3 240) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3 230) at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:33 03) at org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntim e.java:1890) at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:92) at org.mozilla.javascript.gen.c1._c0(scripts/helloworld.js:1) at org.mozilla.javascript.gen.c1.call(scripts/helloworld.js) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:304) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2769) at org.mozilla.javascript.gen.c1.call(scripts/helloworld.js) at org.mozilla.javascript.gen.c1.exec(scripts/helloworld.js) at org.mozilla.javascript.Context.evaluateReader(Context.java:1251) at scripts.javaToJS.main(javaToJS.java:26)=20 ------------------------------------------------ Any help would be appreciated. Thanks, - Aniruddha =20 ---rest deleted--- =20 ------_=_NextPart_001_01C5BF94.7EC0BEE2 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable