First they ignore you
then they ridicule you
then they fight you
then you win
    -- Mahatma Gandhi
Chinese => English     英文 => 中文             
随笔-221  评论-1047  文章-0  trackbacks-0

Groovy 的 Eclipse 插件能够编辑,编译以及运行 groovy 脚本和类

注意这个插件只适用于 eclipse3.1 和 eclipse3.2

最新版本的站点 http://dist.codehaus.org/groovy/distributions/update/

· eclipse 下: Help->Software Updates->Find and Install -> Search For New Features

·选择 New Remote Site

· name 中输入 Groovy

· URL 中复制上述的 URL 地址,然后按下 OK

·在 Select the Features to Install 选上 Groovy ,按下 next

·接受 agreement 并按下 next

·如果默认的地址正确则按下 Finish

·下载完毕后点击 Install 或 Install All

创建 Groovy 工程

·选择 File -> New -> Project

·选择 Java Project 并按下 next

·在 Project Name 中输入 GroovyJava

·在 Project Layout 中选择 Create separate source and output folders 并按下 Finish

·在 Package Explorer 寻找新创建的工程,右键选择 Groovy -> Add Groovy Nature

到目前为止创建的工程中会有一个 src 目录,一个 bin-groovy 目录和几个库文件。 bin 目录被 eclipse 隐藏起来。你需要将 bin-groovy 目录作为默认输出目录连接到 src 目录使得调试器能知道源代码和类文件的关联。

·  在 Package Explorer 中,右击 GroovyJava 工程,选择 Build Path -> Configure Build Path

·  点击 Browse 按钮来改变 Default Output Folder ,从 bin 到 bin-groovy ,按下 ok 。

这时 Package Explorer 中出现 bin 目录,虽然不太清楚 groovy 插件为什么要创建 bin-groovy 目录,也许这里有其他 bin 文件从 groovy 中被分离,或者早期的 eclipse 版本中并不是自动创建 bin 目录。

在 src 中右键创建 groovy class ,并输入例子

class GTest {

  static void main(args) {

      def list = [ "Rod" , "Phil" , "James" , "Chris" ]

      def shorts = list. findAll {it. size () < 5 }

      shorts. each { println it}

  }

}

运行即可

原文地址:http://www.blogjava.net/softwin/archive/2007/04/01/107759.html 作者:伽蓝
附:Groovy轻松入门--Grails实战基础篇

posted on 2007-04-02 05:54 山风小子 阅读(6291) 评论(2)  编辑  收藏 所属分类: Groovy & Grails