Grails 1.1 重用Grails脚本

Grails带了许多开箱即用的命令行功能,你会发现这在你自己的脚本中那个会很有用(查看参考指南的命令行指南部分可以获得所有命令的详细信息)。

尤其是使用 compile 、package 和 bootstrap 脚本。

下边的bootstrap脚本例子允许你启动一个Spring 的 ApplicationContext 实例,通过它来访问数据源等(集成测试时可以这样用):[code]includeTargets << grailsScript(“_GrailsBootstrap”)
target (‘default’: “Load the Grails interactive shell”) {
depends( configureProxy, packageApp, classpath, loadApp, configureApp )
Connection c
try {
// 使用连接做一些事情
c = appCtx.getBean(‘dataSource’).getConnection()
}

finally {
c?.close()
}

}[/code]