(Quick Reference)

run-script

目的
Purpose

Runs one or more custom Groovy scripts, bootstrapping the Grails application first. Gant scripts can't directly call application classes since they aren't on the classpath when the script is compiled. You can load them dynamically but this complicates the scripts.

This script configures the Grails environment, so the Spring application context and Hibernate/GORM are available and you can access the database using domain classes, call service methods, etc.

In addition, the script(s) run in the context of a Hibernate Session to avoid lazy loading exceptions.

使用例
Examples

// run a single script in the dev environment
grails run-script userScripts/createBook.groovy

// run multiple scripts in the dev environment
grails run-script userScripts/someScript.groovy userScripts/otherScript.groovy

// run a single script in the prod environment
grails prod run-script userScripts/updateDatabase.groovy

Also see Ted Naleid's Blog for more usage examples.

詳細
Description

使用方法:

Usage:
grails [environment] run-script [scriptName]

引数:

Arguments:
  • environment - The environment containing the database configuration to use (dev, prod, etc...).
  • scriptName - one or more paths to scripts to run