通过标准JDK 11使用graalvm [英] Use graalvm via the standard JDK 11

查看:784
本文介绍了通过标准JDK 11使用graalvm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Nashorn Javascript引擎的项目.我正在尝试迁移到java11,并且也从Nashorn迁移到Graal.我已经在此处阅读了通过从JDK 11开始的标准JDK安装来使用graal.此外,我还读到Graal-SDK已上载到Maven Central,并且有Java标志polyglot.js.nashorn-compat用于轻松迁移.因此,我使用了jdk11,将maven依赖项添加到pom.xml中,并使用了Java标志,但是当我尝试通过名称"graal.js"获取引擎时,这里的内容为空:

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?

推荐答案

这里是一个示例maven项目,该项目显示了如何通过脚本API和polyglot API在JDK11上运行GraalVM JavaScript引擎.希望对您有帮助!

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

要点是添加必要的依赖项(graal-sdk,js,js-scriptengine,以及可选的profiler和chromeinspector),使用启用的实验选项和JVMCI编译器(-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI)运行并升级模块路径使用格陵兰罐(--upgrade-module-path=${compiler.dir}/compiler.jar),也可以从maven(org.graalvm.compiler:compiler)中获得.

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

这篇关于通过标准JDK 11使用graalvm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆