- import org.junit.Test;
- import org.springframework.scripting.bsh.BshScriptUtils;
- import bsh.EvalError;
- public class TestBeanShell {
- @Test
- public void testShell() {
- String srciptText = "say(name){ return \\"hello,\\"+name;}";
- SayHello sh;
- try {
- sh = (SayHello) BshScriptUtils.createBshObject(srciptText, new Class[] { SayHello.class });
- String res=sh.say("vidy");
- System.out.println(res);
- } catch (EvalError e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- interface SayHello {
- public String say(String name);
- }
- //该片段来自于http://www.codesnippet.cn/detail/1211201410962.html
来源: http://www.codesnippet.cn/detail/1211201410962.html