Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use graalvm via the standard JDK 11

I have project used Nashorn Javascript engine. I'm trying to migrate to java11 and also migrate from Nashorn to Graal. I've read here that I can use graal via the standard JDK installation starting from JDK 11. Also I've read there that Graal-SDK are uploaded to Maven central, and that there is Java flag polyglot.js.nashorn-compat for easy migration. So I've used jdk11, add maven dependency to pom.xml and used java flag but when I'm trying to get engine by name "graal.js", I've got null here:

ScriptEngine engine = engineManager.getEngineByName("graal.js")

What I'm missing? How to make it work?

like image 524
Valentina Chumak Avatar asked Jan 28 '23 06:01

Valentina Chumak


1 Answers

Here is a sample maven project that shows how to run the GraalVM JavaScript engine on JDK11 both through the scripting API and the polyglot API. Hope it helps!

https://github.com/graalvm/graal-js-jdk11-maven-demo

The gist of it is to add the necessary dependencies (graal-sdk, js, js-scriptengine, and optionally profiler and chromeinspector), Run with enabled experimental options and the JVMCI compiler (-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI) and upgrade the module path with the graal jar (--upgrade-module-path=${compiler.dir}/compiler.jar) which is also available from maven (org.graalvm.compiler:compiler).

like image 141
BoriS Avatar answered Jan 31 '23 08:01

BoriS