2011年12月1日 星期四

GWT 在 GPE 中的 Run Configuration

測試環境:Eclipse Indigo、GPE 2.4.2、GWT 2.4.0

GPE 將 GWT(還有 GAE)中許多指令與步驟包裝起來,一方面與 Eclipse 開發環境整合、另一方面盡可能讓我們不用自己下指令設定。不過當開發期間作一些變動時,就會發生無法自動校正對應的狀況。例如 host page 改名字或換位置,Development Mode 的 url 列表不會更新、增加/刪除一個 module 之後沒辦法順利執行...... 等等。

這終究還是得回歸問題的根源來處理。從 Run Configuration 的 Main 頁面我們可以看到 Google 的 Web Application 設定當中,Main class 是指向 com.google.gwt.dev.DevMode,輾轉從 GWT 官方文件得知是在 gwt-dev.jar 這個檔案裡頭,實際手動執行(畢竟官方文件上 java 指令寫的是古老的 HostMode,還是自己來一遍比較安心),會列出 DevMode 的參數格式:


DevMode
[-noserver] 
[-port port-number | "auto"]
[-whitelist whitelist-string]
[-blacklist blacklist-string]
[-logdir directory]
[-logLevel level]
[-gen dir]
[-bindAddress host-name-or-address]
[-codeServerPort port-number | "auto"]
[-server servletContainerLauncher[:args]]
[-startupUrl url]
[-war dir]
[-deploy dir]
[-extra dir]
[-workDir dir] 
module[s]

各參數意義如下:
  • -noserver:執行時不啟動內建的 web server
  • -port:指定內建的 web server 的 TCP port(預設為 8888)
  • -whitelist:讓使用者可以瀏覽符合特定 regular express 條件的網址(用逗號或空格分隔)
  • -blacklist:防止使用者瀏覽符合特定 regular express 條件的網址(用逗號或空格分隔)
  • -logLevel:log 要紀錄到多詳細?值可以是 ERROR、WARN、INFO、TRACE、DEBUG、SPAM、ALL 其中之一。
  • -bindAddress:指定 code server 與 web server 的 IP 位址(預設 127.0.0.1)
  • -codeServerPort:指定 code server 的 TCP Port(預設 9997)
  • -server 指定不同的 web server 當作內建 server(必須 implement ServletContainerLaucher)。例如使用 App Engine 的 server 就會指定com.google.appengine.tools.development.gwt.AppEngineLauncher 為 server。
  • -startupUrl:自動啟動指定的 URL
  • -war:可 deploy 的輸出檔案儲存目錄(預設為 war)
  • -workDir:內部運作時 compiler 的工作目錄(必需要能寫入,預設是系統的暫存目錄)
  • module:指定一個或多個需要載入的 module 名稱,以空白分隔。
除了 module 建議放在最後,其餘參數並無先後順序之分。

有些參數在 GPE 當中測試不出結果,也不知道怎麼翻譯,列舉如後:
  • -logdir:Logs to a file in the given directory, as well as graphically
  • -gen:Debugging: causes normally-transient generated types to be saved in the specified directory
  • -deploy:The directory into which deployable but not servable output files will be written (defaults to 'WEB-INF/deploy' under the -war directory/jar, and may be the same as the -extra directory/jar)
  • -extra:The directory into which extra files, not intended for deployment, will be written
如果要修改上述參數,位置在 Run Configuration→Arguments 頁面→Program arguments 。其中大部分(有用)的參數在 Server、GWT 兩個頁面都可以自動處理。比較特別的是 -startupUrl 這個參數,目前找不到 GPE 自動設定的方式(新增 「Google Web Toolkit→HTML Page」無法正常運作)。它會影響 GPE 的 Development Mode 的 url 列表,如果移除掉這個設定,GPE 就會把 war 目錄下所有 html、jsp 檔都列出來;另外如果有兩個以上的 startupUrl,不能以空格分開 url 的方式設定,而是必須重複 -startupUrl,例如:

-startup /project/portal.jsp -startup index.jsp

寫到這邊,基本上 GPE 裡頭的 Development Mode 已經沒啥秘密了。下次遇到執行有問題時,不妨自己檢查一下 Run Configuration 的 Arguments 設定,應該都可以從中獲得解決。

沒有留言:

張貼留言