Hello,
doles wrote:
> 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?
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/
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino