Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use java class in Graal.js

Using Graal.js, how can I import a java class to script within JS?

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

EDIT: 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?

like image 818
adamM Avatar asked Jun 08 '26 19:06

adamM


1 Answers

add the --jvm arg to the JS command to run Graal.js on JVM, this will allow access to Java objects.

like image 91
adamM Avatar answered Jun 10 '26 10:06

adamM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!