Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.io.File;
import java.io.IOException;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
public class GraalPolyglot {
public static void main(String[] args) throws IOException {
Source source = Source.newBuilder("ruby", new File(args[0])).build();
try (Context context = Context.newBuilder().allowAllAccess(true).build()) {
context.eval(source);
}
}
}
$ java GraalPolyglot test.rb
1
$ java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-20191009173705.graal.jdk8u-src-tar-gz-b07)
OpenJDK 64-Bit GraalVM CE 19.2.1 (build 25.232-b07-jvmci-19.2-b03, mixed mode)
Java.import 'javax.script.ScriptEngineManager'
mgr = ScriptEngineManager.new
js = mgr.getEngineByExtension("js")
js.eval("print(1)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment