Jeff Mesnil
Weblog · Dev · Photos · Books

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

May 14, 2008

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>