Rhino had some extensions and more or less other interpretations on how to combine the Java world with JavaScript. Therefore you cannot simply replace Rhino by Nashorn. One case (which ruined our day) is that you cannot call static methods on instances. Therefore we had to get Rhino up and running in Java 8 until we have our scripts re-written.
Although there is an extensive documentation available in java.net, it is a bit confusing (some URLs are wrong, some steps are missing). So here are the steps which worked for us:
- Download Rhino: https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip
- Download JSR-223: svn checkout svn checkout https://svn.java.net/svn/scripting~svn
Yes that is a ~ in the URL! - cd scripting~svn/trunk/engines/javascript/lib
- Copy the js.jar from rhino1_7R4.zip into this directory (replace the existing js.jar)
- cd ../make
- ant clean all
- Copy ../build/js-engine.jar AND js.jar (of Rhino) into your classpath
- Now change:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
to:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("rhino");
That's all you need to backport Rhino to Java 8.
Update: Here's another tutorial on this Topic: Java 8 Features Tutorial
Super article.
ReplyDeleteJava training in Pune