Skip to content

Instantly share code, notes, and snippets.

@frsyuki
Created October 24, 2019 02:27
Show Gist options
  • Save frsyuki/197b16d429545399dc1b9a5713b32ade to your computer and use it in GitHub Desktop.
Save frsyuki/197b16d429545399dc1b9a5713b32ade to your computer and use it in GitHub Desktop.
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