groovy环境配置:
下载:
http://groovy.codehaus.org/Download
下载:Download zip: Binary Release ----> groovy-binary-1.8.0.zip
1. windows下,增加环境变量:
GROOVY_HOME
D:\java\groovy-1.8.0
path:
%GROOVY_HOME%\bin;
2. linux下,修改环境变量文件:
GROOVY_HOME=/home/javaread/Applications/groovy-1.5.6
PATH=$PATH:$GROOVY_HOME/bin:
export PATH GROOVY_HOME
3. 配置好之后,验证一下Groovy的安装配置是否成功:
执行命令:groovy -v
Groovy Version: 1.8.0 JVM: 1.6.0_10
环境配置也可以参考:
http://wenku.baidu.com/view/d8803e8984868762caaed5fe.html
==========================================================
http://hi.baidu.com/javacookies/blog/item/adeeedf44d0c8a66dcc474b3.html
================================================================
手册网站:
http://www.chinagroovy.org/groovywiki/doku.php
精通Groovy:
http://www.ibm.com/developerworks/cn/edu/j-dw-java-jgroovy-i.html
需要使用Ibm帐号登陆.
一个Groovy&Grails学习资料非常全的博客:
http://www.blogjava.net/BlueSUN/archive/2007/04/23/112978.html
一些Groovy的网站:
http://groovy.codehaus.org Groovy官网
http://groovy.dzone.com Everything for the Groovy & Grails developer
http://www.groovygrails.com Your Source for Groovy / Grails Training
http://grails-exchange.com 著名的Grails交流大会官网,可以找到大会上演说的资料和大会Blog
http://grails.codehaus.org Grails官网
http://pleac.sourceforge.net/pleac_groovy/index.html
http://grails.group.javaeye.com JavaEye的GoG圈子
http://www.groovycn.cn/Html/Index.htmlGroovy中国
http://tech.it168.com/zt/Groovy/index.html 入门可以去看看
http://developer.51cto.com/art/200710/58087.htm
http://www.groovyblogs.org Groovy Blogs
http://www.aboutgroovy.org AboutGroovy 有一些著名的Grails的项目
==========================================================
cacti
http://www.cacti.net/documentation.php
Groovy
http://baike.baidu.com/view/707298.htm
扩展阅读:- 1IBM Developers
- 2http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.0.zip官方下载地址:
- 3http://groovy.codehaus.org官方主页
- 4http://groovy.codehaus.org/Download官方下载页面
Groovy创始人:Java面临终结 Scala将取而代之
http://news.cnblogs.com/n/70574/
Groovy—沉睡的雄狮
http://www.cnblogs.com/cnblogs_2010/archive/2010/08/20/1804154.html
Scala http://baike.baidu.com/view/1588150.htm
Groovy入门教程
http://blog.csdn.net/kmyhy/archive/2009/05/19/4200563.aspx
http://wenku.baidu.com/view/18dabb1ba8114431b90dd8d2.html
http://www.jingege.me/blog/technology/groovy-exec-shell.html
defcommand
="""ping -c1 -W1 hostname"""
// Call *execute* on the string
defproc
=command.
execute()// Wait for the command to finish
proc.
waitFor()// Obtain status and output
println"return code: ${ proc.exitValue()}"
println"stderr: ${proc.err.text}"
// *out* from the external program is *in* for groovy
println"stdout: ${proc.in.text}"
groovy 简单的 cli builder 来构建命令行程序
写 java 的 main 类时,有很多参数,我们都会选择用 apache commons cli 来构建命令行程序。但参数一多,就觉得有点烦琐了。今天发现,groovy 的 CliBuilder 用起来比较简单一些。来看一下示例:
-
- def cli = new CliBuilder()
- cli.h( longOpt: 'help', required: false, 'show usage information' )
- cli.d( longOpt: 'dir', argName: 'dir', required: false, args: 1, 'this is base dir' )
- cli.f( longOpt: 'foo', argName: 'foo', required: true, args: 1, 'this is required option, you must be set' )
- cli.b( longOpt: 'bar', required: false, 'this is boolean option, defalut is false' )
-
- def opt = cli.parse(args)
- if (!opt) { return }
- if (opt.h) {
- cli.usage();
- return
- }
-
- if(opt.d) {
- println 'you use option -d, value:'+opt.d
- }
- if(opt.f) {
- println 'you use option -f, value:'+opt.f
- }
- if(opt.b) {
- println 'you use option -c, value:'+opt.b
- }
运行:
- E:\gsh>groovy cliuse.groovy -d other
- error: -f
- usage: groovy
- -b,--bar this is boolean option, defalut is false
- -d,--dir <dir> this is base dir
- -f,--foo <foo> this is required option, you must be set
- -h,--help show usage information
-
- E:\gsh>groovy cliuse.groovy -f myFoo -d
- error: no argument for:d
- usage: groovy
- -b,--bar this is boolean option, defalut is false
- -d,--dir <dir> this is base dir
- -f,--foo <foo> this is required option, you must be set
- -h,--help show usage information
-
- E:\gsh>groovy cliuse.groovy -f myFoo -d myDir -b
- you use option -d, value:myDir
- you use option -f, value:myFoo
- you use option -c, value:true
E:\gsh>groovy cliuse.groovy -d other
error: -f
usage: groovy
-b,--bar this is boolean option, defalut is false
-d,--dir <dir> this is base dir
-f,--foo <foo> this is required option, you must be set
-h,--help show usage information
E:\gsh>groovy cliuse.groovy -f myFoo -d
error: no argument for:d
usage: groovy
-b,--bar this is boolean option, defalut is false
-d,--dir <dir> this is base dir
-f,--foo <foo> this is required option, you must be set
-h,--help show usage information
E:\gsh>groovy cliuse.groovy -f myFoo -d myDir -b
you use option -d, value:myDir
you use option -f, value:myFoo
you use option -c, value:true
简单解说一下上面的运行结果:第一、没有用 -f 选项,它报错并输出 usage;第二、选项 -d 同有参数,它报错并输出 usage;第三、正确运行。
我认为,以写 main 类,或以用 groovy 代替了,用 groovy 也可以取消配置文件了(groovy 文件可以认为是配置文件)。