jquery in rhino
Asked Answered
S

4

8

I'm trying to load jquery into Rhino as demonstrated by this link here. But I keep getting the following error:

line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null

I think it's that jQuery is failing to load altogether - but I have no idea why. I'm using the same index.html file that the author posted in source control.

Here is the trace from my Rhino console:

js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
    at /temp/jquery.js:1086
    at /temp/jquery.js:1079
    at /temp/jquery.js:16
    at <stdin>:41

Any ideas?

Slapdash answered 23/2, 2011 at 9:27 Comment(0)
S
5

I was using an OLD version of the env.js file. It turns out the author's really ran with it and moved it over to it's own sites, etc, etc.

The new stuff is here.

As soon as I started using it it was golden with jQuery 1.5.

Slapdash answered 23/2, 2011 at 9:52 Comment(2)
I tried your answer but i m still getting 3 runtime error I tried loading all versions of jquery but no success in doing same....Please help me out....+1 in AdvanceBarnes
The only thing I can suggest is use the latest versions of both libraries, that was how I got it to work. The caveat though, is that though it may work in the Rhino console keep in mind that functions like 'load' are only available in the Rhino shell and can not be called in dynamic (runtime from java) code. Good luck.Slapdash
L
3

I don't think jQuery (and many other web JS libraries) will work in Rhino because that JavaScript runtime doesn't provide the expected "browser globals" like "document", "navigator", etc. The error message you list indicates that the library is trying to read an attribute (or call a method) of some (presumably browser) object that doesn't exist in the Rhino environment.

The "env.js" project should do exactly this sort of browser environment mockup but it appears to be experimental and might not be compatible with the version of jQuery you're trying to use.

Laud answered 23/2, 2011 at 9:29 Comment(2)
Can you not set them up somehow? I think that may be the intent behind the env.js from the author.Slapdash
What has me more baffled is the fact that the jQuery dist I have doesn't have anything that seems related on line 1086 - and I can't find 'importNode' anywhere either. :|Slapdash
D
3

I succeeded in running jquery in Rhinojs using instructions from here:

http://geek.michaelgrace.org/2011/09/rhino-and-envjs/

My steps:

wget ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_7R2.zip
wget http://www.envjs.com/dist/env.rhino.1.2.js
wget http://code.jquery.com/jquery-1.8.2.js
unzip rhino1_7R2.zip
java -jar rhino1_7R2/js.jar
load("env.rhino.1.2.js");
load("jquery-1.8.2.js");
Dauphine answered 4/11, 2012 at 23:44 Comment(0)
B
-1

I believe jQuery is useless in Rhino - you have neither DOM nor Ajax. JavaScript 5 (supported in Rhino 1.7R3) has many required fearures, like JSON global object or array methods like forEach() or map().

Burgoo answered 9/12, 2011 at 13:5 Comment(2)
You could load an external file and then you would have a DOM to traverse.Dauphine
envjs.com/doc/guides: "The goal of Envjs is to provide a highly portable javascript implementation of the Browser as a scripting environment ( often referred to as a 'headless' browser )."Dauphine

© 2022 - 2024 — McMap. All rights reserved.