The Grails console
Grails 带了一个Groovy 终端的扩展版本,要运行这个终端只需要在Grails项目的根目录执行下面的命令:
grails console
这个终端是一个Swing GUI界面,他允许你输入任何命令并执行,这是一个不错的学习grails同时测试你的域对象中可用的各种动态查询方法的途径。
The Grails interactive shell
除了这个图形终端,grails还提供了一个交互式的shell,他提供和图形终端类似的功能,但是只有字符界面。要运行这个shell你只需要在grails 项目的根目录执行:
grails shell
在命令执行的时候会有提示教你如何使用它,实际上,你只需要敲入你要执行的命令,每个命令之后跟随一个回车,然后再敲入"go"并回车就可以了。
General usage
Both console and shell are useful for working interactively with your Grails application:
- find domain objects with the help of dynamic finder methods
- call mutator methods on domain objects once you have a reference to them
- save() or delete() domain objects like you would otherwise do in a controller
- ... more to come here
Such an interactive work can be helpful for debugging purposes, for verifying your assumptions about the object state and behavior, to test the effect of dynamic finder methods before putting the code in a controller.
Below is a transcript of an example session with a grails shell for a fictious book store application.
.... more to come here
Packaging a WAR
To package a WAR file for deployment onto an application server you can do:
grails war
By default this will package for a production environment you can change this by doing:
grails test war // for test enviroment grails dev war // for development environment grails prod war // for production
If you want to package for X other environment you can do:
grails -Dgrails.env=blah war