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

5

3 Answers 3

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
1
  • Thanks, that was what I needed to know about where Rhino should / could be installed. Sep 29, 2009 at 12:45
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

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. Sep 29, 2009 at 12:41
  • Did you notice the upvote arrows at the top left of the answers? ;-)
    – Jesper
    Sep 30, 2009 at 11:27
  • Hi Jesper, good point! I did notice the upvote arrows but I need a reputation of 15 or more to use them... Nov 10, 2009 at 13:16
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.

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? Nov 10, 2009 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.