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.
Our typical development environment makes use of the following technologies:
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.
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 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 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 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:
It is MUCH faster than Tomcat & Jetty
No need to restart, it will hot deploy
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 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:
Used to cleanup when a session is destroyedZK Session cleanerorg.zkoss.zk.ui.http.HttpSessionListener
The ZK loader for ZUML pageszkLoaderorg.zkoss.zk.ui.http.DHtmlLayoutServletupdate-uri/zkau1
The asynchronous update engine for ZKauEngineorg.zkoss.zk.au.http.DHtmlUpdateServletzkLoader*.zulzkLoader*.zhtmlauEngine/zkau/*index.htmlindex.htmindex.jspdefault.htmldefault.htmdefault.jspindex.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:
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.
Then we need to specify the dependencies, in this case there are a few:
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.
If you require more information you can take a look at the following documentation: