lucko/helper

Switch to different Javascript engine

Andre601 opened this issue · 4 comments

Considering that Nashorn is deprecated now with Java 11 and may get removed in the future would I suggest to switch to a different engine.

And what would you advise? There aren't many competitors from what I know.

Nashorn has been removed as of Java 15 - https://openjdk.java.net/jeps/372.
This makes running helper-js on 1.17 (which requires Java 16) impossible.

However, it appears Nashorn can be used standalone: https://mail.openjdk.java.net/pipermail/nashorn-dev/2020-October/007557.html

I will edit this issue as I try to get it working. Log:

  • Package is different, helper-js expects jdk.nashorn.api.scripting.NashornScriptEngineFactory, standalone Nashorn has org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory...
    • Transformed the imported package inside helper-js.jar with jarjar as a temporary hack.
  • Added Nashorn with all of its deps into the server jar (classpath wasn't being picked up), no more undefined classes. Seems to load just fine.

Edit: It works, tested on OpenJDK16-OpenJ9:

[12:02:41 INFO]: [helper-js] Enabling helper-js v2.0.0
[12:02:41 INFO]: [helper-js] Loading configuration...
[12:02:41 INFO]: [helper-js] Scanning the classpath to resolve default package imports...
[12:02:41 INFO]: [helper-js] Initialising script controller...
[12:02:41 INFO]: [helper-js] Creating new script environment at plugins/helper-js/scripts (dir/plugins/helper-js/scripts)
[12:02:41 INFO]: [helper-js] [LOADER] Loaded script: init.js
[12:02:42 INFO]: [helper-js] [init] It works!
[12:02:42 INFO]: [helper-js] Done!

@lucko thoughts? The easiest way to support Java 15+ would be to create a separate build artifact which has Nashorn built-in.

It would also be nice if we could load Nashorn like this:

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

instead of explicitly using jdk.nashorn.*. This would allow helper-js to work by just dropping Nashorn into the classpath.