Crash Course In Java Brain Surgery

insinuation and speculations: My thoughts about Java, HTML5, software development and IT in general

Getting Started With Nashorn

Written by  Viktor Gamov -
You can download Early Access Release of JDK8 which include nashorn.jar and jjs JavaScript shell. Add JDK bin directory to PATH with command:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8); export PATH=$JAVA_HOME/bin:$PATH
Type jjs and enter to a JavaScript REPL


While preparing to my JavaOne 2013 talk, I decide to write down some notes about my progress, tip and tricks that descover during my experiments. Consider it as my roadtrip notes. As you learned from my previous post, I’m going to talk about Nashorn - JavaScript engine 100% written in Java. Nashorn will replace Mozilla Rhino in upcoming JDK8. But even today, Nashorn overperfom Rhino in bunch of test. As Rhino, Nashorn is implementing JSR 223: Scripting for the JavaTM Platform. But we will get there.

Getting Nashorn’s sources

  • to download sources from OpenJDK repository. We don’t to mess around with command line tools for Mercurial. And SourceTree available for OSX and Windows.

  • Apache Ant

  • Also you need Mozilla Rhino if you want to run benchmarks to compare Nashorn and Rhino

Build Nashorn For JDK 8

  • Install JDK 8 from here

  • Use JDK 8

  • cd make

  • ant clean; ant

  • Grab latest jar from dist/nashorn.jar


Using Nashorn with JDK7

  • clone Nashorn JDK7 backport

  • build similarly to JDK8 version

  • append boot classpath with

    Augment JDK boot class path with backport Nashonr jar
    export JAVA_OPTS="-Xbootclasspath/a:/YOUR_PATH_TO_NASHORN-BACKPORT_DIR/dist/nashorn.jar"