How to best install Rhino on OSX 10.6 Snow Leopard
Asked Answered
O

3

6

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

Orethaorferd answered 27/9, 2009 at 21:53 Comment(5)
You should be able to do this using the JDK jrunscript tool (Rhino is packaged with Java 6) developer.apple.com/mac/library/documentation/Darwin/Reference/…Natale
That bundled version of Rhino is not Rhino1_7R2, and it doesn't include E4X, unfortunately.Self
I installed Rhino by following this article - ejohn.org/blog/bringing-the-browser-to-the-server - but it was on Leopard, not Snow Leopard. I don't think it should matter, though.Draughtboard
both Alex and Jesper have been helpful, I would Vote them up if I had 15 reputation.Orethaorferd
and now that my 'reputation' has increased I have indeed Voted them upOrethaorferd
D
7

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
Dandify answered 28/9, 2009 at 1:10 Comment(1)
Thanks, that was what I needed to know about where Rhino should / could be installed.Orethaorferd
D
6

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

Disgusting answered 28/9, 2009 at 8:33 Comment(3)
Thanks, I found the same that it's not in PATH although using the full path you give does indeed run jrunscript in the shell. I will see if adding a symbolic link, or adding it to ~/.profile can make the path shorter.Orethaorferd
Did you notice the upvote arrows at the top left of the answers? ;-)Disgusting
Hi Jesper, good point! I did notice the upvote arrows but I need a reputation of 15 or more to use them...Orethaorferd
F
2

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.

Fluorescence answered 9/11, 2009 at 15:52 Comment(1)
Thanks for that information! It encourages me to persevere with Rhino. Where would you install Rhino 1.7? In /usr/local/ as I did or somewhere else? You mention using an alias, what two paths would you use it to connect?Orethaorferd

© 2022 - 2024 — McMap. All rights reserved.