# Grails 1.1 重用Grails脚本

**URL:** <https://www.isharkfly.com/t/grails-1-1-grails/1812>\
**Category:** 程序语言\
**Created:** [November 3, 2012, 3:41pm UTC](https://www.isharkfly.com/t/grails-1-1-grails/1812 "2012-11-03T15:41:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [November 3, 2012, 3:41pm UTC](https://www.isharkfly.com/t/grails-1-1-grails/1812/1 "2012-11-03T15:41:29Z")

</div>

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]
