Skip to content

Instantly share code, notes, and snippets.

@mgttt
Forked from dekosuke/gist:1002198
Created November 7, 2016 00:04
Show Gist options
  • Save mgttt/2ae686f665d90ed7f5a223f58519922b to your computer and use it in GitHub Desktop.
Save mgttt/2ae686f665d90ed7f5a223f58519922b to your computer and use it in GitHub Desktop.
JavaからJavaScript(Rhino)呼び出し
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public class ScriptingForJavaScript {
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("js");
try {
engine.eval("print(\"Hello, JavaScript!\")");
} catch (ScriptException ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment