Drawing Hands by M.C. Escher (1948)

Jeff Mesnil


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

On May 14th, 2008 in apple, java, javascript, macosx

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>

4 Responses to “How to include JavaScript engine in Apple’s Java 6 VM”

  1. Alexander O'Neill Says:

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

  2. Ben Says:

    Thanks indeed, this helped a lot.

  3. 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…

  4. Matt Stine Says:

    Awesome! This was very helpful. – Matt

Leave a Reply