How does one load a library such as jQuery or prototype into the rhino
context when running as an embedded app within a java program? I am
using Java 6, rhino 1.7R2. I can totally run functions and eval
arbitrary code, but I cant find any documentation or even class files
in the source tree that scream to me "use me to load libraries". So
what class/method in Rhino actually satisfies the load (file)
semantics in the command line?
Thanks for your attention!
Sachin
rhino is "just" an interpreter of javascript, if you want use jquery
or prototype you need a browser environment (DOM, and many of other
things).
a project exist for rhino : env-js http://github.com/thatcher/env-js
This is an javascript implementation of a browser env for rhino.
have fun
Quentin
Alternatively, you can check out latest CVS version and use the CommonJS support in it (look for org.mozilla.javascript.commonjs.module.Require class)
Attila.
--
home: http://www.szegedi.org
twitter: http://twitter.com/szegedi
weblog: http://constc.blogspot.com
We use Prototype in our server application, via the JSR-223 API, by
providing a host object that offers a "load()" method.
In other words:
public class FileLoader {
ScriptEngine engine;
Bindings bindings;
(...)
public Object load(String filePath) {
File path = new File(filePath);
Object result = engine.eval(new FileReader(path), bindings);
return result;
}
(...)
}
when initializing the bindings:
(...)
bindings.put("fileLoader", new FileLoader());
(...)
and from JavaScript you can then use:
(...)
fileLoader.load("prototype.js");
(...)
For Prototype, we modified the code so that the parts that require a
browser environment are essentially commented out.
This is the idea. To keep my post simple I left out many details, but if
you want, let me know and I can elaborate. :)
Hope this helps,
-Christian
--
Christian Grigis
Senior Software Engineer
NEXThink S.A. -- http://www.nexthink.com/