How can I start coding with Oracle's Nashorn JS Engine and when will it replace Rhino in the OpenJDK?

max picture max · Nov 17, 2012 · Viewed 12.2k times · Source

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.

Answer

pd40 picture pd40 · Nov 17, 2012

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 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:

The Nashorn repo is in the process of being migrated to OpenJDK and as such is incomplete in several areas. The build system is not fully integrated. When complete, Nashorn will be installed in its proper location in the JRE. Once integrated, the correct version of the JDK will be wrapped around Nashorn. In the meantime, ensure you use JDK8 b68 or later.

If you checkout nashorn~jdk8 from source you can build nashorn.jar

cd nashorn~jdk8/nashorn/make
ant clean; ant

You can request the "nashorn" engine from javax.script.ScriptEngineManager in a recent jdk 1.8 build:

jrunscript -cp ./nashorn.jar -l "nashorn" -e "println(engine.factory.getParameter(
    javax.script.ScriptEngine.ENGINE))"
> Oracle Nashorn

or with nashorn.jar in the path:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");

Update Mar 19, 2014:

Update from @ncasas; JDK 8 is out and Nashorn is the default JS engine.