JDK6引入javax.script.* API能够把任何脚本或动态语言无缝地嵌入到具有一致编程API的JAVA应用程序中。
/** * 通过 javax.script API 调用脚本 * */public class ScriptEngineManagerTest { public static void main(String[] args) throws ScriptException, NoSuchMethodException{ ScriptEngineManager scriptEngineMgr = new ScriptEngineManager(); ScriptEngine groovyEngine = scriptEngineMgr.getEngineByName("groovy"); groovyEngine.eval("println 'hi,welcome!'"); groovyEngine.eval("def a='jack';println 'hi,'+a+'!'"); }}