Sohaib Zafar
Sohaib Zafar

Reputation: 193

Nashorn alternative for Java 11

I am using the Nashorn JavaScript Engine in Java 11 which works fine except it will be deprecated soon. I have tried GraalVM which I find quite worse as it takes 13-14 seconds to execute a simple expression (e.g. 2+3). Is there any other alternative that I could use or should I try GraalVM with some other approach (if there is any)?

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("javascript");
engine.eval("2+3");

Upvotes: 17

Views: 18523

Answers (2)

Sheinbergon
Sheinbergon

Reputation: 3063

Update (June 2022):

As of 2022, it seems J2V8 is also poorly maintained.

Better set your sights on Javet


If someone still finds this question relevant, a viable, still actively maintained alternative to Nashorn/Rhino script engines is the J2V8 binding for the JVM.

Artifacts can be found here (be sure to use this link to get updated releases)

Multi-platform support is builtin via JNI

Though its mechanics are a bit different than those of the ScriptEngine API, performance is (as expected) better. and you don't have to deal with weird side effects like unintended class-loading caused by misuse of the API.

I have successfully used it myself in the past.

Upvotes: 5

Ori Marko
Ori Marko

Reputation: 58862

You can use Rhino as replacement

Rhino still is being maintained as an open-source project and so has a history of community involvement. For some uses, it’s clearly superior because of its faster startup time.

Upvotes: 3

Related Questions