感谢作者,本文转载:http://topic.csdn.net/u/20080319/14/c3cca464-d2bf-4356-bcb0-ebdf0958b04e.html
事先准备:
1、zk最新版本
2、myeclipse
开始研究ZK,为了便于开发,开始设置环境,网络上一扑,发现很不错的文章,摘自如下:
完美的解决方案:
一 :创建用户自定义库。
在eclipse里打开window->preferences->java->build path->user libraries,如下所示:将“%ZK_HOME%/dist/lib目录下的所有jar文件(如果需要更多ZK附加功能,加入ext与zkforge目录下的jar文件).
点击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.xsd到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.vtl文件的内容如下所示:
<?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/jsp/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/jsp/zul http://www.zkoss.org/jsp/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开发环境。