2011年6月24日 星期五

Play Framework 實驗筆記 2- Play! Framework 環境設定

1. 安裝
這個部份比較簡單,大部分資訊網路上都有。Google 一下就有了~~
Source由官網 http://www.playframework.org/download 下載 play-1.1.zip 直接解壓後就可以使用

2. 建立專案
N:\PlayFramework\play-1.1>play new members

N:\PlayFramework\play-1.1>"N:\PlayFramework\play-1.1\python\python.exe" "N:\Play
Framework\play-1.1\play" new members
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.1, http://www.playframework.org
~
~ The new application will be created in N:\PlayFramework\play-1.1\members
~ What is the application name? [members]
~
~ OK, the application is created.
~ Start it with : play run members
~ Have fun!
~

N:\PlayFramework\play-1.1>

3. 安裝Plugin for PlayFramework

3.1. SIENA
package models;
N:\PlayFramework\play-1.1>play install siena

N:\PlayFramework\play-1.1>"N:\PlayFramework\play-1.1\python\python.exe" "N:\Play
Framework\play-1.1\play" install siena
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.1, http://www.playframework.org
~
~ Will install siena-1.5
~ This module is compatible with: 1.1
~ Do you want to install this version (y/n)? y
~ Installing module siena-1.5...
~
~ Fetching http://www.playframework.org/modules/siena-1.5.zip
~ [--------------------------100%-------------------------] 32.9 KiB/s
~ Unzipping...
~
~ Module siena-1.5 is installed!
~ You can now use it by add adding this line to application.conf file:
~
~ module.siena=${play.path}/modules/siena-1.5
~

3.2. GAE
package models;
N:\PlayFramework\play-1.1>play install gae

N:\PlayFramework\play-1.1>"N:\PlayFramework\play-1.1\python\python.exe" "N:\Play
Framework\play-1.1\play" install gae
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.1, http://www.playframework.org
~
~ Will install gae-1.4
~ This module is compatible with: 1.1, and GAE 1.4.0
~ Do you want to install this version (y/n)? y
~ Installing module gae-1.4...
~
~ Fetching http://www.playframework.org/modules/gae-1.4.zip
~ [--------------------------100%-------------------------] 32.9 KiB/s
~ Unzipping...
~
~ Module gae-1.4 is installed!
~ You can now use it by add adding this line to application.conf file:
~
~ module.siena=${play.path}/modules/gae-1.4
~

記得加入這兩行,到 N:\PlayFramework\play-1.1\member1\conf\application.conf

module.gae=${play.path}/modules/gae-1.4
module.siena=${play.path}/modules/siena-1.5


4. 將專案匯出到eclipse
這個三不五時可以作一次,例如你新增module 到你的application.conf 後,記得重新匯出到eclipse,這樣相關的lib才會載入到eclipse project
package models;
N:\PlayFramework\play-1.1>play eclipsify members

N:\PlayFramework\play-1.1>"N:\PlayFramework\play-1.1\python\python.exe" "N:\Play
Framework\play-1.1\play" eclipsify members
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.1, http://www.playframework.org
~
~ OK, the application is ready for eclipse
~ Use File/Import/General/Existing project to import N:\PlayFramework\play-1.1\m
embers into eclipse
~
~ Use eclipsify again when you want to update eclipse configuration files.
~ However, it's often better to delete and re-import the project into your works
pace since eclipse keeps dirty caches...
~
然後開啟Eclipse 之後,用File下面的 Import,選擇 General/Existing project 後到指定路徑就可以Import 專案。


5. 啟動專案
package models;

N:\PlayFramework\play-1.1>play run members

N:\PlayFramework\play-1.1>"N:\PlayFramework\play-1.1\python\python.exe" "N:\Play
Framework\play-1.1\play" run members
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/
~
~ play! 1.1, http://www.playframework.org
~
~ Ctrl+C to stop
~
Listening for transport dt_socket at address: 8000
23:09:07,000 INFO  ~ Starting N:\PlayFramework\play-1.1\members
23:09:08,515 WARN  ~ You're running Play! in DEV mode
23:09:09,468 INFO  ~ Listening for HTTP on port 9000 (Waiting a first request to
 start) ...
6. 開啟瀏覽器,並連線到 http://127.0.0.1:9000/
看到以下的圖片,代表專案已經正常執行