Web程序中應用Gwt

Gwt在 Web 項目中的應用,Gwt適用各種Web項目,通過Java代碼生成JavaScript代碼。

通過Eclipse Helios 的 Google Plugin 插件創建 Web 工程:

File -> New  -> Other..


 

Next ->



 

Finish ->

創建好的Project:



 

運行 GwtTest:

右鍵工程GwtTest -> Run As.. -> Web Application -> 打開 Development Mode 試圖


 雙擊試圖上面的地址,此時會打開默認的瀏覽器。如圖



 這是一個簡單的例子。


 這種運行方式爲開發模式,可以進行Debug調試:

在需要的地方設置斷點(Ctrl+Shift+B) ->  右擊工程  ->  Debug As.. -> Web Application 即可。

 

另一種運行方式爲生產模式:真正發佈工程的運行方式:

在方步之前需要先編譯Java源代碼生成JavaScript代碼 -> 右擊工程 -> Google -> GWT Compile


 

彈出編譯窗口:



 

選中要編輯的文件 -> Compile ,此時控制檯會輸出一些編譯的信息:

Compiling module com.demo.GwtTest
   Compiling 6 permutations
      Compiling permutation 0...
      Compiling permutation 1...
      Compiling permutation 2...
      Compiling permutation 3...
      Compiling permutation 4...
      Compiling permutation 5...
   Compile of permutations succeeded
Linking into C:\Documents and Settings\admin\workspace\GwtTest\war\gwttest
   Link succeeded
   Compilation succeeded -- 36.921s

 

編譯完成之後,在war文件夾目錄下會生成許多文件。此時可以部署到 Tomcat 中

<Context path="/gwttest" docBase="C:\Documents and Settings\admin\workspace\GwtTest\war" />

此時啓動服務器,然後在瀏覽器輸入http://127.0.0.1:8080/gwttest/GwtTest.html 此時和剛剛的運行效果一樣。

 

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章