ZK for eclipse

來源:互聯網
上載者:User

 ZK是一個很優秀的AJAX架構,號稱"Ajax framework without javascript",有點像GWT的實現,但是與GWT的完全案頭開發思想不同,它支援用ZUL,一種ZK的介面指令碼來寫介面,開發效率很高,介面也很漂亮,具體的介紹可以去看看它的首頁:http://www.zkoss.org。但是很可惜的是,ZK目前還沒有Eclipse的外掛程式,但是利用MyEclipse提供的相關工具,我們可以建立一個差強人意的開發環境出來,本文就對此環境的建立做了具體介紹,本文的環境是JDK6.o+Eclipse3.3+MyEclipse6.0M+ZK2.4.1。

          首先,去http://www.zkoss.org下載最新版的ZK,目前是2.4.1,下載開發包以及demo,下載的開發包裡有ZK的開發庫,以及用到的庫,還有一些擴充庫,另外就是ZK的源碼,其中開發包下的dist目錄結構如下所示:

          ├─lib
│     │     zcommon.jar
│     │     zhtml.jar
│     │     zk.jar
│     │     zkplus.jar
│     │     zul.jar
│     │     zweb.jar
│     │
│     ├─ext
│     │         bsh.jar
│     │         commons-el.jar
│     │         commons-fileupload.jar
│     │         commons-io.jar
│     │         Filters.jar
│     │         groovy.jar
│     │         jcommon.jar
│     │         jfreechart.jar
│     │         jruby.jar
│     │         js.jar
│     │
│     └─zkforge
│             dojoz.jar
│             fckez.jar
│             gmapsz.jar
│             json_simple.jar
│             timelinez.jar

├─src
│         zcommon-sources.jar
│         zhtml-sources.jar
│         zk-sources.jar
│         zkplus-sources.jar
│         zul-sources.jar
│         zweb-sources.jar

├─WEB-INF
│     └─tld
│         ├─web
│         │         core.dsp.tld
│         │         html.dsp.tld
│         │
│         ├─zk
│         │         core.dsp.tld
│         │
│         └─zul
│                 core.dsp.tld

└─xsd
           zul.xsd

          將這個目錄下的所有檔案都拷貝到一個專門的目錄,(我一般喜歡把經常用到的第三方庫放在一個專門的檔案夾裡,並且在eclipse裡建立對應的user library),比如我放在d:/EclipseUserlib/ZK下。

         第二步,建立使用者自訂庫。在eclipse裡開啟window->preferences->java->build path->user libraries,如所示:

 

 

如所示,點擊New按鈕可以建立一個新的使用者庫,點擊建好的庫後,啟用Add Jars...按鈕,可以添加這個使用者庫相關的jar包,這裡我們建立三個使用者庫,即ZK Ajax Frame、ZK Ajax Framework Extendsion以及ZK Ajax Framework Forge Library三個,分別對應上面目錄結構中的lib、ext以及zkforget。

         另外一個小trick,點開jar包前的+號,可以看到有一個source attachment,雙擊它可以出來一個對話方塊,讓你選源檔案所在地,這裡選擇上面目錄下的src檔案夾下的對應檔案,這樣就可以在eclipse裡使用代碼瀏覽功能。         第三步,添加xsd到使用者xml catalog entry裡。這是為了確保我們可以更好的地使用MyEclipse XML Editor的功能。開啟window->preferences->MyEclipse->Files and Edtors->XML->XML Catalog,如所示: 點擊Add,在彈出對話方塊裡添加上面目錄中的zul.xml到catalog中。

          第四步:添加自己的自訂xml產生wizard。          開啟%MyEclipse安裝目錄%/eclipse/plugins/com.genuitec.eclipse.wizards_5.9.100,其中templates/xml是用來存放xml檔案模板的,這裡我們需要產生如下幾個檔案:          LangAddon.vtl
          Portlet.vtl
          ZK.vtl
          ZKWeb.vtl
          ZUL.vtl          前四項分別對應zkdemo/WebContent/WEB-INF下的lang-addon.xml、portlet.xml,zk.xml和web.xml,只需要把這些檔案拷貝到xml目錄下,並且對應修改檔案名稱為上述檔案名稱即可。另外注意:開啟每個vtl檔案,第一行由“<?xml version="1.0" encoding="UTF-8"?>”修改為“<?xml version="1.0" encoding="$encoding"?>”。      其中ZUL檔案的內容如下所示:<?xml version="1.0" encoding="$encoding"?>
<?page title="title" ?>
<!--
action.zul

{{IS_NOTE
Purpose:

Description:

History:
Tue Oct 25 09:51:30       2005, Created by tomyeh
}}IS_NOTE

Copyright (C) 2005 Potix Corporation. All Rights Reserved.

{{IS_RIGHT
}}IS_RIGHT
-->
<zk xmlns="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul ">
</zk>       然後修改%MyEclipse安裝目錄%/eclipse/plugins/com.genuitec.eclipse.wizards_5.9.100/templates.xml,在<!-- XML Templates -->後面添加如下內容:    <template
    context="com.genuitec.eclipse.wizards.xml"
    script="templates/xml/ZKWeb.vtl"
    name="XML template for a web.xml file with ZK capability"/>
    <template
    context="com.genuitec.eclipse.wizards.xml"
    script="templates/xml/LangAddon.vtl"
    name="XML template for a lang-addon.xml file for ZK"/>
    <template
    context="com.genuitec.eclipse.wizards.xml"
    script="templates/xml/Portlet.vtl"
    name="XML template for a port-let.xml file for ZK"/>
    <template
    context="com.genuitec.eclipse.wizards.xml"
    script="templates/xml/ZK.vtl"
    name="XML template for a zk.xml file"/>
    <template
    context="com.genuitec.eclipse.wizards.xml"
    script="templates/xml/ZUL.vtl"    name="XML template for a *.zul file"/>儲存後重新開啟eclipse。    第五步,添加新的檔案類型。開啟window->preferences->general-content types,如所示:其中給Java Source File添加*.zs,給XML添加*.zul,給JSP添加*.dsp,給HTML添加*.zhtml。

        到此在MyEclipse下我們已經搭建了一個簡易但是實用的ZK開發環境。        如何利用此環境開發ZK應用,請看文章“利用MyEclipse建立的ZK開發環境開發ZK應用”。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.