Jeff Mesnil

How to include JavaScript engine in Apple’s Java 6 VM

After complaining in my previous post, here is a more constructive guide to use JavaScript with Apple’s Java 6 VM:

  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:

public class JavaScriptTest {
    public static void main(String[] args) throws Exception {
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        engine.eval("print('hello, world!')");
    }
}

jrunscript is also working:

    $ cd /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home/bin/
    $ ./jrunscript 
    rhino-nonjdk> print("hello, world");
    hello, world
    rhino-nonjdk>

Posted by on May 14, 2008

Comments

  • Thanks so much for posting this, this had me scratching my head for half a day.

  • Ben says:

    Thanks indeed, this helped a lot.

  • Kjell Arne says:

    Thank you very much for posting this. I missed out on the jsr223-engines library, and couldn’t figure it out. This is standard Java feature on every other platform, but why am I not surprised Apple only has AppleScript support in their JDK…

  • Matt Stine says:

    Awesome! This was very helpful. – Matt

  • Comments closed