Groovy

来自开放百科 - 灰狐
2018年5月6日 (日) 06:14Allen (讨论 | 贡献)的版本

跳转到: 导航, 搜索
Wikipedia-35x35.png 您可以在Wikipedia上了解到此条目的英文信息 Groovy Thanks, Wikipedia.
Groovy-90x90.png

Groovy于2003年8月由James Strachan(与Bob McWhirter开发,开发以开放源代码的形式进行。“Java是非常强大而且优秀的语言,但源代码量往往很大”(Strachan)。而脚本语言的优点就是简单方便,在Java中描述非常复杂的部分,如果使用脚本语言可以提高效率。不过,目前的脚本语言中还存在问题,“要想使脚本与Java应用共存,必须通过脚本生成Java的字节码,而如果语法差异很大开发人员就很费劲。我们还希望使用J2EE与J2SE的API”(Strachan)。但符合这一要求的脚本语言并不存在。“因此通过开发人员,使Java的开发和运行环境更加符合‘groovy’”(Strachan)。如果使用Groovy,有时开发时间要比Java缩短一半。由于Groovy的代码中也有描述Java代码的机制,因此两者合用非常容易。

Groovy不仅继承了Java的语法,还吸取了Ruby、Python、Perl等其他脚本语言的特征。如List(列表)与数组等使用特有的语法,提高了描述效率。在会议中,使用从列表中收录的多个字符串中搜索4个字符以下的字符串并显示出来的处理,演示了Groovy的效率。在Java中必须要15 行以上,在Groovy中4行便可以描述。

当然与Java相比,Groovy也有不足之处,比如性能,目前“根据不同的使用方法,为Java的20~90%左右。今后还将进行细节调整”(开发 Groovy的Rod Cope)。此外Groovy还存在不支持内隐类(Inner Class)、调试(Debug)有困难等课题。不过“对小型且不太关键的系统特别有效。也非常容易掌握,因此请务必试一试”(Cope)。Groovy 的运行环境可以从官方网站下载。

Grails

目录

简介

Apache Groovy

Groovy语言核心由java语言编写而成。

新闻

为什么Groovy

  • 因为JVM
  • 因为Java动态语言;
  • 因为DSL(Groovy是Java平台的DSL,它是有限领域的Java开发的理想选择;可以将Groovy视为 “简略的Java语言” 更能说明Groovy与Java语言之间的关系);
  • 因为Gradle, Moqui 等优秀项目;
  • 因为Apache顶级项目

安装

OS X

通过Homebrew安装groovy

$ brew install groovy
$ brew upgrade groovy

通过port安装groovy

sudo port install groovy
groovy -v
sudo port upgrade groovy // 升级到新版本
groovysh // Groovy Shell

Linux

wget http://dist.groovy.codehaus.org/distributions/groovy-binary-1.5.1.zip
GROOVY_HOME=C:\groovy-1.5.1\ or /usr/local/groovy-1.5.1
add path %GROOVY_HOME%\bin or %GROOVY_HOME%/bin
groovyConsole.bat
In the top part of the window of the groovyConsole, type the following
println "Hello, World!" 
type <CTRL-R>
groovy> println "Hello, World!"

安装成功

测试

class Greet {
    def name
    Greet(who) { name = who[0].toUpperCase() +  who[1..-1]}
    def salute() { println "Hello $name!" }
    }
    g = new Greet('world')
    g.salute()

显示结果

Hello World!

Examples

Groovy 入门经典 (Groovy Programming) 的随书例子

Modules

  • COM Scripting — script Windows ActiveX and COM components with Groovy
  • Gant
  • GFreeMarker — an integration of the FreeMarker template engine for Groovy
  • Google Data Support — makes using the Google Data APIs easier from within Groovy
  • Gram — a simple xdoclet-like tool for processing doclet tags or Java 5 annotations
  • GraphicsBuilder — GraphicsBuilder is a Groovy builder for Java 2D
  • Grapplet
  • Griffon — Dekstop Enhancements for Groovy
  • Groosh — Provides a shell-like capability for handling external processes.
  • Groovy Jabber-RPC — allows you to make XML-RPC calls using the Jabber protocol
  • Groovy Monkey — is a dynamic scripting tool for the Eclipse Platform
  • Groovy SOAP — create a SOAP server and make calls to remote SOAP servers using Groovy
  • GroovyLab — Provides a domain specific language (DSL) for math engineering (matlab-like syntax).
  • GroovySWT — a wrapper around SWT, the eclipse Standard Widget Toolkit
  • GroovyWS — GroovySOAP replacement that uses CXF and Java5 features
  • GSP — means GroovyServer Pages, which is similar to JSP (JavaServer Pages)
  • GSQL — supports easier access to databases using Groovy
  • JideBuilder — JideBuilder is a Groovy builder for the open source JIDE Common Layer
  • Native Launcher — a native program for launching groovy scripts
  • Windows NSIS-Installer — a Windows-specific installer for Groovy
  • Windows Services — framework for Groovy-based WinNT (Windows) Services
  • WingSBuilder — WingsBuilder is a Groovy builder for the wingS Framework
  • XMLRPC — allows you to create a local XML-RPC server and/or to make calls on remote XML-RPC servers
  • Grails — a Groovy-based web framework inspired by Ruby on Rails
  • GORM — the Grails Object-Relational Mapping persistence framework
  • GroovyPlugin — A Groovy plugin for JSPWiki
  • Maven Plugin — Integration of Groovy with Maven

项目

文档

图集

链接

Groovy.png
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱