1. 程式人生 > >Groovy入門-1

Groovy入門-1

Groovy 是 Java平臺上指令碼語言,抽象程度更高(可以更簡單的快速開發,可以編寫更少的程式碼)
與Java語言無縫整合,可稱為“超級Java”
1.使用“類Java”語法,Java程式設計師可以快速過渡。
2.Groovy與Java二進位制相容,都可以生成位元組碼,所以可以與使用Java語言所編寫的框架和元件完美整合,並且效率安全方面比其他指令碼語言更高。
3.Groovy物件就是Java物件,使用與JDK相同的API.
4.可以保護整個Java產業在Java上的巨大投資。
在中小型專案中可以替代Java,在大型Java專案中可以嵌入Groovy應用。

Groovy的特徵


Groovy = Java - 重複程式碼
+ 可選的動態型別
+ 閉包(closures)
+ 領域規範語言(DSL)
+ 生成器(builders)
+ 超程式設計(metaprogramming)
Groovy 是沒有型別、修飾符、return、Iterator,不需要匯入集合的Java。Groovy丟掉了許多Java的報復。
不能確定變數型別時將變數型別設為Object。
DSL:domain specific languages
生成器:可以生成XML/HTML/Swing樹形資料結構
超程式設計:執行時對類增加行為,類似於AOP

由於idea有預設對Groovy的支援,這裡就不多闡述Idea對於Groovy的使用,在這裡闡述一下eclipse對Groovy的使用。

Eclipse-Groovy 外掛

News
Date News
Mar 4, 2016 Groovy Eclipse snapshot builds for Eclipse 4.6 are available! Update site: http://dist.springsource.org/snapshot/GRECLIPSE/e4.6/
Jun 6, 2015 Groovy Eclipse 2.9.2 snapshot builds for Eclipse 4.5 are available, update site http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/


Jan 24, 2015 Groovy Eclipse 2.9.2 snapshot builds for Eclipse 4.4 now include Groovy 2.4.0, update site http://dist.springsource.org/snapshot/GRECLIPSE/e4.4/ NOTE installing this will downgrade your Eclipse JDT because it does not include the latest version. This may introduce problems that have since been fixed in JDT. If you see any JDT issues try uninstalling this first to confirm whether it is really Eclipse that is to blame or the patched compiler in here
November 18, 2014 Groovy Eclipse 2.9.1 Released. This release includes support for the latest Groovy 2.3.7, improved to QuickFixes, type inference and other bug fixes. Read more in the [[Groovy Eclipse 2.9.1 Release Notes]]
July 17, 2014 Groovy Eclipse 2.9.0 Released. This release includes support for the latest Groovy 2.3.4 compiler with features such as Traits. Read more in the [[Groovy Eclipse 2.9.0 Release Notes]]
July 9, 2013 Groovy Eclipse 2.8.0 Released. This release includes significant memory and performance improvements, as well as Editor templates and almost 100 bugs fixed. Read more at the Groovy-Eclipse 2.8.0 New and Noteworthy.
Releases

The latest Groovy-Eclipse release is available from the following Eclipse update sites. To install, point your Eclipse update manager to the update site appropriate for your Eclipse version.
Eclipse Level Release Update Site
4.4 (Luna) http://dist.springsource.org/release/GRECLIPSE/e4.4/
4.3 (Kepler) http://dist.springsource.org/release/GRECLIPSE/e4.3/
4.3-8 (Kepler with Java 8) http://dist.springsource.org/release/GRECLIPSE/e4.3-j8/
4.2 and 3.8 (Juno) http://dist.springsource.org/release/GRECLIPSE/e4.2/
3.7 (Indigo) http://dist.springsource.org/release/GRECLIPSE/e3.7/

Or, you can choose to install a development build, see below for more update sites. In general, our development builds are quite stable.

The install directory must be writable by the current user. Groovy-Eclipse cannot be installed into a shared install. This includes protected directories on windows like C:\Program Files. For more information Eclipse Bug 395516.
Snapshot Builds

Use one of these update sites to install the latest and greatest Groovy-Eclipse. Development builds tend to be quite stable (they are not released unless all tests pass). To install, paste the appropriate update site below into your Eclipse update manager, select the artifacts to install and follow the instructions.
Eclipse Level Snapshot Update Site
4.6 (Neon) http://dist.springsource.org/snapshot/GRECLIPSE/e4.6/
4.5 (Mars) http://dist.springsource.org/snapshot/GRECLIPSE/e4.5/
4.4 (Luna) http://dist.springsource.org/snapshot/GRECLIPSE/e4.4/
4.3-j8 (Kepler with Java 8 patch) http://dist.springsource.org/snapshot/GRECLIPSE/e4.3-j8/
4.3 (Kepler) http://dist.springsource.org/snapshot/GRECLIPSE/e4.3/
4.2 and 3.8 (Juno) http://dist.springsource.org/snapshot/GRECLIPSE/e4.2/
3.7 (Indigo) http://dist.springsource.org/snapshot/GRECLIPSE/e4.2/
How to Install

Start with a compatible version of Eclipse (available from http://eclipse.org/downloads). Since Groovy-Eclipse relies on Eclipse’s Java tooling (the JDT), almost any flavor of Eclipse that includes the JDT will be compatible. This includes the Java IDE, Classic, RCP, JavaEE, etc. Flavors such as Eclipse for PHP developers are not compatible because it does not include the JDT> If you are interested in Grails tooling, then you must install the Groovy/Grails Tool Suite.

Once you have a compatible Eclipse installed, then follow these directions to install Groovy-Eclipse:

Go to: Help -> Software Updates.
Change to the Available Software tab.
Click on Add Site.
Paste the update site URL appropriate for your version of Eclipse and click OK.
You should see a “Groovy Update Site” entry in the list of update sites. Expand and select the Groovy-Eclipse Plugin
feature. Optionally, you can choose to include the sources..
Click Install and follow the prompts.
Restart when asked
Rejoice! You installed the Groovy-Eclipse Plugin.

Developer Resources

Source code hosted on GitHub
The Bamboo CI Server for Groovy-Eclipse.
Submit bugs on the Codehaus Jira Issue Tracker.
How to [[Update Greclipse to a New Groovy Compiler Version|Updating the groovy in groovy eclipse]]
Overview of [[Groovy Eclipse Architecture]]
How to [[Build the Maven Batch Compiler|Building Maven Batch Compiler]]
[[Release Build Process]]

這裡寫圖片描述

這裡寫圖片描述

由於我這裡下載成功,無法顯示Next的按鈕,可能由於網速原因會出現下載失敗,但是由於我的不放棄的精神,終於經過多次下載失敗之後,成功下載。。。雖然一度使Eclispe啟動失敗。。。

下載成功之後將會出現

這裡寫圖片描述