1. grails create-app myproject (创建名为myproject的grails应用工程)

2. grails install-plugin flex (安装grails的flex插件,首次安装的话会比较慢,因为会下载很多Flex和BlazeDS的jar文件)

3. grails create-service Hello (生成一个HelloService.groovy, 在grails-app/services目录下), 编辑该文件:
   1class HelloService {  
   
2.   
   
3.     static expose = ['flex-remoting']  
   
4.   
   
5.     boolean transactional = true  
   
6.    
   
7.     def hello() {  
   
8.         return "Hello,world!"  
   
9.     }  
  
10.   
  
11. }             


4. 编写flex客户端, 比如main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:RemoteObject id="ro" destination="helloService"/>

<mx:Button label="Hello" click="ro.hello()"/> <mx:TextInput text="{ro.hello.lastResult}"/>

</mx:Application>

5. 使用grails run-app 启动服务器
6. 访问http://localhost:8080/sample/bin/sample.mxml,或者http://localhost:8080/sample/bin/sample.html
   点击“Hello”,就可以显示Hello world了

注意:如果无法访问编译sample.mxml生成的sample.html,则需要指定两个参数
 1) 指定-services参数为web-app/WEB-INF/flex/services-config.xml(相对或绝对路径都可),
 2) 指定-context-root参数为web的context,如本例中为sample