No JavaScript in Java 6 on Mac OS X

I was writing some code that uses Rhino. Rhino is a open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. Rhino is included in Java 6 from Sun but NOT on the Mac! They took it out and only have support for AppleScript. I found this blog letting me know they took it out.

Fix:
Then I found this blog which explains how to fix the problem.

  1. Download JSR 223’s engines
  2. Copy jsr223-engines/javascript/build/js-engine.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/
  3. Download Rhino
  4. Copy rhino1_7R1/js.jar to /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/lib/ext/

You can now use a “JavaScript” engine from Apple’s Java 6 VM:

Your code will look something like this.


ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
engine.eval("print('hello, world!')");

Comments (View)

Comments powered by Disqus