I\'m looking for a way to start playing around with Oracle\'s new Nashorn JavaScript Engine. I\'ve DL\'d the latest OpenJDK 8 (b65) and it appears that Rhino is still the on
I've done some more digging around and you can get Nashorn working with JDK7 by using a backport of it located here:
https://bitbucket.org/ramonza/nashorn-backport
Checkout that repository and attempt to build it using ant -f make/build.xml
as described on the BitBucket page
Apply the patch listed in the issues section here if you get a failed build due to dynalink (I assume it will be patched into the main repository soon by the developer).
Upon building it you should get a nashorn.jar file inside the dist folder of your cloned repository.
Now you need to add this jar to your bootclasspath using a VM option similar to this:
-Xbootclasspath/a:C:/nashorn-backport/dist/nashorn.jar
And now you should be able to use nashorn. To make sure here's a quick test program I wrote that will list out the available engine factories:
import javax.script.*;
public class NashornTest {
public static void main(String args[]) {
ScriptEngineManager manager = new ScriptEngineManager();
for (ScriptEngineFactory f : manager.getEngineFactories()) {
printBasicInfo(f);
System.out.println();
}
}
public static void printBasicInfo(ScriptEngineFactory factory) {
System.out.println("engine name=" + factory.getEngineName());
System.out.println("engine version=" + factory.getEngineVersion());
System.out.println("language name=" + factory.getLanguageName());
System.out.println("extensions=" + factory.getExtensions());
System.out.println("language version=" + factory.getLanguageVersion());
System.out.println("names=" + factory.getNames());
System.out.println("mime types=" + factory.getMimeTypes());
}
}
Running that with the bootclasspath set will list Rhino and Nashorn, without it you will only see Rhino.