Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to execute multiple javascript files at the same time

4 views
Skip to first unread message

lind...@gmail.com

unread,
May 14, 2007, 6:25:31 PM5/14/07
to
Hi,

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

Jason Wadsworth

unread,
May 14, 2007, 8:16:18 PM5/14/07
to dev-tech-...@lists.mozilla.org
Just execute the scripts within the same scope. This essentially the
same as putting all the code in a single file.

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

lind...@gmail.com

unread,
May 15, 2007, 6:24:22 AM5/15/07
to
Hi Jason,

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

Jason Wadsworth

unread,
May 15, 2007, 9:39:45 AM5/15/07
to dev-tech-...@lists.mozilla.org
I don't know about BSF.

Maybe you could try the BSF mailing list.

http://jakarta.apache.org/site/mail2.html#BSF

0 new messages