就是想体验GraalVM使用多语言的时候报错
public static void main(String[] args) { System.out.println("Hello World from Java!"); Context context = Context.newBuilder().allowAllAccess(true).build(); context.eval("js", "print('Hello World from JavaScript!');"); context.eval("python", "print('Hello World from Python!')"); context.eval("ruby", "puts 'Hello World from Ruby!'"); }
报错信息
Exception in thread "main" java.lang.IllegalArgumentException: A language with id 'js' is not installed. Installed languages are: []. at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineException.illegalArgument(PolyglotEngineException.java:131) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.throwNotInstalled(PolyglotEngineImpl.java:1105) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotEngineImpl.requirePublicLanguage(PolyglotEngineImpl.java:1112) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.requirePublicLanguage(PolyglotContextImpl.java:1502) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.lookupLanguageContext(PolyglotContextImpl.java:1464) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1473) at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:63) at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:403) at org.graalvm.sdk/org.graalvm.polyglot.Context.eval(Context.java:429) at icu.yujing.blog.GraalVMTest.main(GraalVMTest.java:19) 进程已结束,退出代码为 1
提示没安装 安装就好了(未配置graalvm的环境变量时, 应在graalvm包下的bin目录执行命令)
PS F:\ProgramsDev\JDK\graalvm-jdk-17.0.8+9.1\bin> .\gu install js Downloading: Artifacts catalog from gds.oracle.com Skipping ULN EE channels, no username provided. Downloading: Component catalog from www.graalvm.org Processing Component: Graal.js Processing Component: ICU4J Processing Component: TRegex Additional Components are required: ICU4J (org.graalvm.icu4j, version 23.0.1), required by: Graal.js (org.graalvm.js) TRegex (org.graalvm.regex, version 23.0.1), required by: Graal.js (org.graalvm.js) Downloading: Component js: Graal.js from gds.oracle.com Downloading: Component org.graalvm.icu4j: ICU4J from gds.oracle.com Downloading: Component org.graalvm.regex: TRegex from gds.oracle.com Installing new component: TRegex (org.graalvm.regex, version 23.0.1) Installing new component: ICU4J (org.graalvm.icu4j, version 23.0.1) Installing new component: Graal.js (org.graalvm.js, version 23.0.1)
graalvm是什么?如何使用?
You can use GraalVM like a Java Development Kit (JDK) in your IDE.
您可以在IDE中像Java开发工具包(JDK)一样使用GraalVM。