2011年8月11日

使用 apt-get 安裝 Grails 以 Ubuntu 11.04 Natty 為例

Grails 為 SpringSource 的開放源碼專案,它受到 Ruby on Rails 敏捷的開發方式啟發,實現了 MVC 架構,並提供大量的 Plug-ins 可供專案取用,目標是成為使用 Java EE 開發 Web 2.0 網站應用的框架。

這段影片可以幫助您瞭解 Grails 的開發方式。


使用 Java EE 的開發框架,最容易讓初學者詬病的地方,就是安裝基本開發環境,也有不少瑣碎的設定。Grails 的安裝雖然不難,只要在裝有 JDK 的作業系統下,解壓縮下載的 Grails 檔案,設定好相關 PATH 就可以運作。

但如果您使用 Ubuntu Linux,那過程就可以更加簡單!

以下的指令說明,是以 Ubuntu Linux 11.04 為例。

首先,使用以下的指令,增加 apt repository 的設定(Ubuntu的PPA套件庫)。
sudo add-apt-repository ppa:groovy-dev/grails
sudo apt-get update

使用 apt-get install 即可完成 Grails 的安裝。
sudo apt-get install grails

在 Ubuntu 系統可以同時安裝不同版本的 Grails,使用 apt-cache search 可以查詢哪些 Grails 版本可供安裝。
apt-cache search grails

輸出:
grails-1.3.1 - A rapid web development platform built on Groovy
grails-1.3.2 - A rapid web development platform built on Groovy
grails-1.3.0 - A rapid web development platform built on Groovy
grails-2.0.0 - A rapid web development platform built on Groovy
grails-1.3.7 - A rapid web development platform built on Groovy
grails-1.4.0 - A rapid web development platform built on Groovy
grails-bash-completion - Provides bash autocompletion for Grails, a rapid web development platform built on Groovy
grails - A rapid web development platform built on Groovy
grails-1.2.5 - A rapid web development platform built on Groovy


如果要加裝 Grails 2.0.0 (目前為 Milestone 測試版),則加上版號。
sudo apt-get install grails-2.0.0

也可以安裝較早的舊版本。
sudo apt-get install grails-1.2.5

使用 update-alternatives 可以切換 Grails 的不同版本。
sudo update-alternatives --config grails

輸出:
There are 2 choices for the alternative grails (providing /usr/bin/grails).


  Selection    Path                                   優先級  Status
------------------------------------------------------------
* 0            /usr/share/grails/1.3.7/bin/grails      50        auto mode
  1            /usr/share/grails/1.3.7/bin/grails      50        manual mode
  2            /usr/share/grails/2.0.0.M1/bin/grails   1         manual mode


Press enter to keep the current choice[*], or type selection number: 

參照系統已安裝的 Grails 版本清單,輸入數字就可以完成切換。

輸入 grails 就可以檢視目前的版本編號。
grails

輸出:
Welcome to Grails 1.3.7 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /usr/share/grails/1.3.7

以往在效能不彰的電腦(尤其是筆電),開發 Java EE 專案相當痛苦,其執行速度之慢,真是每次 Deploy & Test 的時間都足夠泡杯咖啡看部短片。

以 Grails 的開發來說,大部分的專案開發過程的操作,都可以使用 Command-Line 的指令完成。例如「grails create-controller name」,就可以建立 MVC 架構中的控制器程式。並不需要依賴肥大的開發環境,而且程式碼撰寫也像 PHP / Ruby 之類的 Scripting Language 同樣簡單(雖然有些程式仍需要經過編譯才執行)。

因此在開發 Grails 的環境,只需要一(或多)個終端機畫面,搭配 Ubuntu Gnome 內建的 Gedit 文字編輯器,就可以節省不少系統效能的消耗(肥大的整合開發環境是記憶體殺手)。關於 Grails 搭配 Gedit 編輯器的客製化設定,可以參考這篇教學

沒有留言:

張貼留言

lyhcode by lyhcode
歡迎轉載,請務必註明出處!