Groovy安装与入门实例

2 篇文章 0 订阅

 

1 Groovy是什么?


来看下官网的介绍:http://groovy.codehaus.org

===============================================================================

Groovy...

·        is an agile and dynamic language for the Java Virtual Machine

·        builds upon the strengths of Javabut has additionalpower features inspiredby languages like Python, Ruby and Smalltalk

·        makes modern programming features available to Java developers with almost-zero learning curve

·        provides the ability to statically type check and staticallycompile your codefor robustness and performance

·        supports Domain-Specific Languages and other compact syntax so your codebecomes easyto read and maintain

·        makes writing shell and buildscripts easy with its powerfulprocessing primitives, OO abilities and an Ant DSL

·        increases developer productivity by reducing scaffolding code when developing web, GUI, database orconsole applications

·        simplifies testing bysupporting unit testing and mocking out-of-the-box

·        seamlessly integrates with all existingJava classes and libraries

·        compiles straight to Java bytecodeso you can use it anywhere you can use Java

===============================================================================

 

通过支持DSL提高代码可读性和可维护性

减少开始Web、GUI、数据库、控制台应用程序时的脚手架代码

简化单元测试和Mock技术

与Java类包无缝集成

 

2 Groovy环境安装


下面是官方文档中摘取的安装步骤。适用于Linux系统或Cygwin模拟环境。如果是Windows平台的话,也可以直接下载Windows installer一键安装。

===============================================================================

GVM (the GroovyenVironment Manager)

This tool makesinstalling Groovy on any Bash platform (Mac OSX, Linux, Cygwin, Solaris orFreeBSD) very easy.

Simply open a newterminal and enter:

$ curl -s get.gvmtool.net | bash

Follow theinstructions on-screen to complete installation.

Open a newterminal or type the command:

$ source "$HOME/.gvm/bin/gvm-init.sh"

Then install thelatest stable Groovy:

$ gvm install groovy

After installationis complete and you've made it your default version, test it with:

$ groovy -version

That's all thereis to it!

===============================================================================

 

下面来亲自体验一下,然后编写个Groovy版的Hello World测试一下。

 

$ curl –s get.gvmtool.net | bash


 

之后执行初始化脚本,也可以将这句命令加入到~/.bashrc中。

 

$ source "/cygdrive/c/Users/daichen/.gvm/bin/gvm-init.sh"

 

编写一个Hello World试一下吧。

 

helloworld.groovy

===============================================================================

class Test {

def text = “helloworld!!!”

}

print new Test().getText()

===============================================================================

 

         $ groovy helloworld.groovy

         hello world!!!

 

3 Groovy-Eclipse插件安装


在Help -> Install New Software下输入http://dist.springsource.org/release/GRECLIPSE/e3.6

选择Groovy-Eclipse (Required) 进行安装。

 

可以新建Groovy项目,或者在已有项目中新加Groovy Class,就会自动开启此项目上的Groovy Nature属性。这样普通Java代码就与Groovy代码融合在一起了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值