Use graalvm via the standard JDK 11

Valentina Chumak :

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?

BoriS :

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).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=75325&siteId=1