We are always being asked about our environment setup within the ZK office and how to setup a ZK environment. First of all this blog will cover the typical development environment of a ZK developer. It will not cover setting up an environment to develop ON ZK, at least not yet.

So without further ado let’s go forth.

Technologies

Our typical development environment makes use of the following technologies:

  • Eclipse
  • ZK Studio
  • Maven (m2)
  • Run-Jetty-Run

All of these technologies are employed on a regular basis within ZK. In fact main development work on ZK is generally done using this environment. There are exceptions as in any development house.

The following diagram outlined the above technologies and describes how the technologies are employed to make our jobs as developers easier.

You can of course substitute some technologies we use for your favourites.

Let’s look at the technologies one at a time.

Eclipse

For internal development we tend to prefer Eclipse. This is not a must set down by the powers that be, just a personal choice of a lot of developers within ZK. For the remainder of this post I will assume that you are using Eclipse.

You can download Eclipse here. Please make sure you download the version for Java EE Developers.

ZK Studio

ZK Studio is a shoe-in for use within ZK. It provides a lot of ZK related functionality such as content assistance, WYSIWYG visual development, Ajax widget palette and many more.
For more information please take a look at the product page.

Maven

Maven is awesome…

After many years using Java I did get into JAR hell a few times which caused lots of problems. The fact that this can now all be managed via a tool really is a lifesaver.
If you haven’t tried Maven do it now. There is an initial learning curve but once you get over it you won’t go back.

Run-Jetty-Run

Run Jetty Run is a project maintained by one of ZK’s core developers, Tony. At the moment Run-Jetty-Run is the servlet container of choice in the company for the following reasons:

  1. It is MUCH faster than Tomcat & Jetty
  2. No need to restart, it will hot deploy
  3. Debugging is fully supported

I have found using Run-Jetty-Run has significantly increased my personal productivity substantially over using Tomcat which I previously did.

Installing

Installing is very easy, each of the technologies I just outlined are available on the Eclipse marketplace or come with their own update sites.
You should search the marketplace first as this is the latest (and easiest) way of installing them in my opinion.

First ZK Maven project

Having installed everything it is now time to create a sample ZK application using Maven. First thing’s first, start to create your maven project.

Then choose the maven archetype web application.

Fill out the appropriate information such as the Group Id and artifact id. If you are unfamiliar with these concepts you should take a look at a Maven tutorial. For Group Id I used “test.me” and the Arifact Id just “application.”

Having done that click finish and you will have your web application. Now we change the contents of web.xml to provide the ZK defaults:



	ZKTwitterService
	
		
		Used to cleanup when a session is destroyed
		ZK Session cleaner
		org.zkoss.zk.ui.http.HttpSessionListener
	
	
		
		The ZK loader for ZUML pages
		zkLoader
		org.zkoss.zk.ui.http.DHtmlLayoutServlet
		
			update-uri
			/zkau
		
		1
	
	
		
		The asynchronous update engine for ZK
		auEngine
		org.zkoss.zk.au.http.DHtmlUpdateServlet
	
	
		zkLoader
		*.zul
	
	
		zkLoader
		*.zhtml
	
	
		auEngine
		/zkau/*
	
	
		index.html
		index.htm
		index.jsp
		default.html
		default.htm
		default.jsp
		index.zul
	

At this point you can create a zk.xml in the same location as your web.xml but it is not necessary unless you want some specific ZK settings. I just add a blank one.



	

We now need to let Maven know what dependencies are required for ZK. This is exceptionally easy.

Firstly I give Maven some properties:


	5.0.7.1
	1.1.0
	2.4
	2.0b4
	1.2.1
	1.3.1
	1.1.1
	2.4
	2.0.235

Then I follow this up by telling Maven where it can find the ZK libraries. In this case I use ZK CE. For PE and EE please follow this documentation.


	
		ZK CE
		http://mavensync.zkoss.org/maven2
	

Then we need to specify the dependencies, in this case there are a few:


	
		commons-logging
		commons-logging
		${commons-logging.version}
	
	
		commons-fileupload
		commons-fileupload
		${commons-fileupload.version}
	
	
		commons-io
		commons-io
		${commons-io.version}
	
	
		org.zkoss.zk
		zk
		${zk.version}
	
	
		org.zkoss.zk
		zkplus
		${zk.version}
	
	
		org.zkoss.zk
		zul
		${zk.version}
	
	
		org.zkoss.zk
		zhtml
		${zk.version}
	
	
		org.zkoss.common
		zcommon
		${zk.version}
	
	
		org.zkoss.common
		zweb
		${zk.version}
	
	
		org.zkoss.zkforge.el
		zcommons-el
		${zkel.version}
	
	
		commons-lang
		commons-lang
		${commons-lang.version}
	

I have actually left out a lot of jar files which supply zscript support for ruby, groovy, python and javascript as I very rarely use these in projects unless prototyping. These can of course be added very easily but I prefer to start with the core jars and then add as I need them. If you want to see all the options please click here.

Upon saving the pom file Maven will update the dependencies and download the appropriate ZK JARs. At this point create a zul file named index.zul in the webapp directory. Here are my contents:


	

Then right click the file, Run-as -> Run on Jetty. The server will run and point your browser to the appropriate URL, in my case http://localhost:8080/application/index.zul.

I have put the source on github, you can get it here.

More information

If you require more information you can take a look at the following documentation:

Run-jetty-Run
ZK Studio Essentials
Maven with ZK

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply