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 only included script engine.
Anyone know when (or in which build) Nashorn will replace Rhino in the OpenJDK? Or even better, where I can get a JDK with it included already? I know Netbeans has already written a debugger to use it, just not sure where they got the libraries/code to start writing it.
Anyone have some links?
Thanks.
Install the JDK8 and create an alias for your JDK's jjs (Nashorn Interpreter), e.g., if you create a file called test.js, you can run the program with:
Mac OS = alias jjs=’/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/bin/jjs’
Windows = Define an environment variable called ‘JAVA8_HOME’ and point to your jdk8 folder, then you can invoke jjs by running this command:
I've been looking at how to use it recently and I currently think the only way you can start using it is if you build the OpenJDK from source as it isn't in the current version from the 7th of February.
I assume it will be in the developer preview version released later this week though (21/02/2013).
Source: http://openjdk.java.net/projects/jdk8/
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 pageApply 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:
Running that with the bootclasspath set will list Rhino and Nashorn, without it you will only see Rhino.
It looks like there is no sign of Nashorn on OpenJDK yet.
The most recent comment from Jim Laskey in Oct 2012 suggests Q4 2012:
https://blogs.oracle.com/nashorn/entry/welcome_to_the_nashorn_blog#comment-1351205506968
I think it is time for a nashorn tag on SO!
Update Dec 1 2012:
Looks like late Dec 2012 OpenJDK may have it https://blogs.oracle.com/nashorn/entry/request_for_project_nashorn_open
Update Mar 10, 2013:
@Seth is correct that 1.7 release 3 PRERELEASE is not Nashorn. My mistake!
JDK 8 b68 includes a yet to be merged nashorn~jdk8 branch.
The README for this branch says:
If you checkout nashorn~jdk8 from source you can build nashorn.jar
You can request the "nashorn" engine from javax.script.ScriptEngineManager in a recent jdk 1.8 build:
or with nashorn.jar in the path:
Update Mar 19, 2014:
Update from @ncasas; JDK 8 is out and Nashorn is the default JS engine.