Subj : Re: How to call one JavaScript's method in another JavaScript To : Anupriya From : Igor Bukanov Date : Mon Feb 10 2003 08:54 pm Anupriya wrote: > > Actually I want to define my few constants or methods in one java > script file and want to call them from another java script file lying > in the same directory. > Rhino shell provides the load function which you can use to call scripts from other files, see http://mozilla.org/rhino/shell.html . You can add support for all shell functions to your application if you replace call to Context.initStandardObjects(null) in your code by new org.mozilla.javascript.tools.shell.Global(cx), like in the following modification of examples/RunScript.java from the Rhino distribution. import org.mozilla.javascript.*; public class RunScriptEx { public static void main(String args[]) throws JavaScriptException { // Creates and enters a Context. The Context stores information // about the execution environment of a script. Context cx = Context.enter(); try { // Initialize the standard objects (Object, Function, etc.) // This must be done before scripts can be executed. Returns // a scope object that we use in later calls. //Scriptable scope = cx.initStandardObjects(null); // Use shell scope instead Scriptable scope = new org.mozilla.javascript.tools.shell.Global(cx); // Collect the arguments into a single string. String s = ""; for (int i=0; i < args.length; i++) { s += args[i]; } // Now evaluate the string we've colected. Object result = cx.evaluateString(scope, s, "", 1, null); // Convert the result to a string and print it. System.err.println(cx.toString(result)); } finally { // Exit from the context. Context.exit(); } } } Regards, Igor .