I am using Rhino to execute javascript code from my java application.
So far, I can successfully execute one javascript file by calling:
Context.evaluateString( myScriptFile1 );
But my business logic could be complicated, so I would like to
separate them into multiple javascript files: e.g.
In myScriptFile1.js, I define functions like:
function myFunc() {
// do something
}
Then I have myMainJS.js, in which I call the function in
myScriptFile1.js
How can I do this? It looks that the Shell can load multiple js files,
but how can I do it from my java app?
Thanks
Here's an example:
//create a global scope containing the standard javascript
objects
ScriptableObject scope = context.initStandardObjects();
//Evaluate the script which defines your utility functions,
using 'scope' as the global context
context.evaluateReader(scope, new FileReader("functions.js"),
"functions.js", 1, null);
//Evaluate the script that uses the utility functions in the
same scope.
context.evaluateReader(scope, new FileReader("process.js"),
"process.js", 1, null);
Jason Wadsworth
> _______________________________________________
> dev-tech-js-engine mailing list
> dev-tech-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine
Thank you very much for your response.
In my app, I actually would like to use BSF to execute the scripting
code because I would like to use scripting language not only
JavaScript, so BSF can choose the correct engine at the runtime.
For now, I can use bsfmanager.eval() to execute one script file.
Similarly, how can I execute multiple script files ( in the same
scripting language) from BSF?
Thanks
Maybe you could try the BSF mailing list.
http://jakarta.apache.org/site/mail2.html#BSF