Skip to content

Instantly share code, notes, and snippets.

@dekosuke
Created June 1, 2011 14:16
Show Gist options
  • Save dekosuke/1002364 to your computer and use it in GitHub Desktop.
Save dekosuke/1002364 to your computer and use it in GitHub Desktop.
JavaからJavaScript(Rhino)呼び出し JavaObjectのKey
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");
Object obj= new Object();
engine.put("obj", obj);
try {
engine.eval("println(obj);");
engine.eval("for (var i in obj) { println(i); }");
} catch (ScriptException ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment