在Graal.js中使用Java类 [英] Use java class in Graal.js
问题描述
使用Graal.js,如何在JS中导入Java类以编写脚本?
Using Graal.js, how can I import a java class to script within JS?
以下代码适用于Nashorn JJS,但不适用于Graal.js,因为graal中没有Java.type()
,我是否需要在某个时候调用松露?
The following code works with Nashorn JJS, but does not work with Graal.js because there is no Java.type()
in graal, do I need to invoke truffle at some point?
var ArrayList = Java.type("java.util.ArrayList");
var myList = new ArrayList();
myList.add("hello");
myList.add("world");
print(myList);
我能够使用--jvm
参数将其导入Java类型,这似乎表明它是在JVM上运行的.那么,这是否完全通过GraalVM并仅使用JVM?
I was able to get it to import java types using the --jvm
paramter, which seems to indicate that it runs it on the JVM. So does this completely pas over the GraalVM and just use the JVM?
推荐答案
将--jvm arg添加到JS命令以在JVM上运行Graal.js,这将允许访问Java对象.
add the --jvm arg to the JS command to run Graal.js on JVM, this will allow access to Java objects.
这篇关于在Graal.js中使用Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!