I am running OSX 10.6 Snow Leopard, have downloaded rhino1_7R2 and moved it to /usr/local/
I am aware however that (while this would prevent it from being altered by OS updates) this may not be the best location for it and imagine that it may need to be connected to the Java installation.
My intended use for Rhino is to run JavaScript from the Terminal command line, and I'm asking for help as I believe I lack the Java knowledge to quickly figure this out.
I would appreciate any help or links to advice,
thanks Paul
I have not used Rhino before, but I just quickly grabbed 1.7R2 from Mozilla and tried it out. It appears to be a standard Java jar executable. The location of it as compared to Java is irrelevant (as it should be).
All you need to do to run it, in your case, would be something like the following (from Terminal.app):
java -jar /usr/local/rhino1_7R2/js.jar
I noticed that this particular program is actually starts a interactive JS shell, which may not be what you wanted (but it may be), but if you run it with -help, you will see its full usage:
java -jar /usr/local/rhino1_7R2/js.jar -help
Note that since Java 6, the scripting API is built-in in the standard Java library, and you really don't need a third-party library like Mozilla Rhino anymore. (In fact, the scripting API in Java 6 is an adapted version of Mozilla Rhino).
See the API documentation for the package javax.script
and see: Scripting for the Java Platform.
The default version of Java on Mac OS X 10.6 (Snow Leopard) is Java 6, so you should be able to use the standard scripting API without installing anything special.
Note: I found that jrunscript
is installed on my Mac, but for some reason it's not in the PATH so it can't find it if I type jrunscript
in a terminal. In my file system, it's here:
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/jrunscript
As jrunscript has been mentioned in other answers & comments, it's a convenient tool, but it doesn't support full Javascript 1.5.
$ jrunscript -q
Language ECMAScript 1.6 implemention "Mozilla Rhino" 1.6 release 2
Javascript 1.5 is fully supported as of Rhino 1.6R6, and Rhino 1.7 supports JavaScript 1.7.
Rhino 1.6Rx is supposed to support E4X, but curiously this simple exemple fails in jrunscript:
$ jrunscript -e 'toto = <tata/>'
script error: sun.org.mozilla.javascript.internal.EvaluatorException: erreur de
syntaxe (<string>#1) in <string> at line number 1
And I had troubles making jrunscript work with John Resig's env.js (that allows to load jQuery, Prototype, and other libs in Rhino scripts), because 1.6R2 doesn't implements get & set properties (they were added in 1.6R6 IIRC).
More info on Rhino versions here:
So I think Rhino 1.7R2 is better for you, as you already have it. Just use an alias or something to make the command line shorter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With