2013-04-03 48 views
0

在Web应用程序中包含Groovy控制台的最佳方式是什么?我可以在其中输入代码并查看输出结果?在测试阶段检查/调试生活应用程序将非常方便。如何在JavaEE Web应用程序中包含Groovy控制台

我发现these tools但我没有看到他们在maven回购。所以我认为可能还有别的东西。我也看到this question。它指向grails console plug-in。但在我看来,需要一个我不想要的Grails项目。我只想要一个可以用maven配置文件激活的控制台。我希望现在有其他选择。

回答

3

你应该看看GroovyShell。它直接使用Groovy下载包(groovy-2.1.2.jar)。你可以传递一个groovy脚本并提供一些数据绑定。

例如:

final String script = "1+x"; 
try 
{ 
    final Map<String, Object> ctx = new HashMap<String, Object>(); 
    ctx.put("x", 5); 
    final Binding binding = new Binding(ctx); 
    final Object result = new GroovyShell(binding).evaluate(script); 
    System.out.println(result); 
} 
catch (final GroovyRuntimeException e) 
{ 
    // something bad happend - e.g. script error 
    e.printStackTrace(); 
} 

的周围的东西包括到你的web应用应该是直线前进。

+1

+1,你可以在[the]找到grails插件的UI(https://github.com/burtbeckwith/grails-console/blob/master/grails-app/taglib/org/grails/plugins/ console/ConsoleTagLib.groovy)[source](https://github.com/burtbeckwith/grails-console/blob/master/grails-app/views/console/index.gsp)[code](https:// github。 com/burtbeckwith/grails-console/tree/master/web-app/js)repo –

+0

谢谢,这看起来很简单,但我希望只需添加一个依赖项并准备好页面。但是这样我可以添加一些本来不可用的绑定。 – akostadinov

相关问题