Setup the Development Directory

Our first task is to setup the development directory; including putting all required libraries of ZK into the development directory, and editing related configuration files.

Structure of Development Directory

Try to create a development directory under the web application directory of Tomcat(ex.$TOMCAT_HOME/webapps). The structure of development directory is shown below:


+ProjectName
  +META-INF
  +WEB-INF
    +classes
    +lib
    web.xml
    zk.xml
  +src
  web pages
  • WEB-INF/web.xml defines required definitions of servlets, and listeners for running ZK application.
  • WEB-INF/zk.xml is the configuration descriptor of ZK.(Optional)
  • WEB-INF/classes include all of Java Class files.
  • WEB-INF/lib includes required libraries of ZK

    Required jar file of this application are listed below.

  • ZK
    • bsh.jar: BeanShell Java code interpreter
    • commons-el.jar: Apache implementation of Expression Language (EL) interpreter
    • zcommon.jar: The common library for ZK
    • zhtml.jar: XHTML-related components
    • zk.jar: ZK kernel code
    • zkplus.jar: integration codes for Acegi Security, Spring, Hibernate, and data binding
    • zul.jar: XUL-related components
    • zweb.jar: Web-related utility codes
  • HSQLDB
    • hsqldb.jar: Hsql Database
  • src/ includes source files.
  • web pages could be put under the home directory directly or its decedent directories.

Configuration of web.xml

The second step is to define required servlets,and listeners for ZK in web.xml.


<!-- ZK -->
  <listener>
    <description>Used to clean up when a session is destroyed</description>
    <display-name>ZK Session Cleaner</display-name>
    <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
  </listener>

  <servlet>
    <description>ZK loader for ZUML pages</description>
    <servlet-name>zkLoader</servlet-name>
    <servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
    <init-param>
      <param-name>update-uri</param-name>
      <param-value>/zkau</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zul</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>zkLoader</servlet-name>
    <url-pattern>*.zhtml</url-pattern>
  </servlet-mapping>

  <servlet>
    <description>The asynchronous update engine for ZK</description>
    <servlet-name>auEngine</servlet-name> 
    <servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>auEngine</servlet-name>
    <url-pattern>/zkau/*</url-pattern>
  </servlet-mapping>