Create and Run Your First ZK Application Manually"

From Documentation
m (Created page with '{{ZKInstallationGuidePageHeader}} =Create your first application= Here is how to create a Web application manually without IDE or other tools. It is easy to find the similar pro…')
 
 
(32 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{ZKInstallationGuidePageHeader}}
 
{{ZKInstallationGuidePageHeader}}
 +
=Prepare the server=
 +
 +
==Install Tomcat==
 +
First, you have to prepare a Web server. You can use any Web servers that support Java Servlet (2.3 or later). Here we introduce the installation of [http://tomcat.apache.org Tomcat]. For other servers and more information, please refer to [[ZK_Installation_Guide/Setting_up_Servers|Setting up Servers]].
 +
 +
#Visit [http://tomcat.apache.org/ Tomcat Official Site]
 +
#Select the correct binary distribution for your environment and download
 +
#* For Windows, you might download and execute [http://apache.stu.edu.tw//tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.exe 32-bit/64-bit Windows Service Installer], and then follow the instructions
 +
#* For any download/installation problems, please refer to http://tomcat.apache.org/tomcat-6.0-doc/index.html
 +
 +
==Download ZK Libraries==
 +
 +
ZK libraries can be downloaded from [http://www.zkoss.org/download/zk.dsp ZK Download] and then save it to a proper location.
 +
 
=Create your first application=
 
=Create your first application=
  
Here is how to create a Web application manually without IDE or other tools. It is easy to find the similar procedure with your preferred IDE or tools, such as Eclipse and NetBeans.
+
Here shows you how to create a web application manually without IDE or other tools.  
  
==Download ZK==
+
==Create Web application==
 +
ZK Web Applications use a standard directory structure defined in the Servlet specification.
  
First, download the ZK libraries from http://www.zkoss.org/download/zk.dsp and save it to a proper location.例如zk-bin-5.0.4.zip
+
When developing ZK web applications, you must follow this structure so that the application can be deployed in any J2EE compliant web servers.
  
==Create a Web application==
+
''All you need to do is create a web application directory  with related files.''
 +
[[File:J2EEWebApplication.jpg]]
  
Creating a Web application is easy: just create some directory.
 
  
:myZK
+
*Now i create one for example named <span style="color:green">'''myZK'''</span>
:myZK/WEB-INF
+
===Install Library Distribution===
:myZK/WEB-INF/lib
+
#Unzip zk-bin-x.x.x.zip (the ''x.x.x'' is the latest version)
 +
#Copy JAR files under  following list to <u>'''myZK'''/WEB-INF/lib</u>
 +
#:* {YOUR_ZK_UNZIP_FOLDER}/dist/lib 
 +
#:* {YOUR_ZK_UNZIP_FOLDER}/dist/lib/ext
 +
#:* {YOUR_ZK_UNZIP_FOLDER}/dist/lib/zkforge
  
===Deploy ZK libraries===
+
===Create Deployment Descriptor(Web.xml)===
1. Unzip zk-bin-5.0.4.zip
+
<u>web.xml</u> is called the web application deployment descriptor. This is an XML file that defines servlets, servlet mappings, listeners, filters, welcome files etc.  
2. Copy JAR files under dist/lib            to myZK/WEB-INF/lib
 
3. Copy JAR files under dist/lib/ext      to myZK/WEB-INF/lib
 
4. Copy JAR files under dist/lib/zkforge to myZK/WEB-INF/lib
 
  
===Create web.xml===
+
The deployment descriptor is a heart of any J2EE web applications, so ''every web application '''must have''' a web.xml deployment descriptor directly under <u>WEB-INF</u> folder''.
  
Create web.xml under myZK/WEB-INF. For the content of web.xml, please refer to [http://books.zkoss.org/wiki/ZK_Installation_Guide/Before_You_Start/Sample_of_web.xml Sample of web.xml]
+
*For the content of <u>web.xml</u>, please refer to [[ZK_Installation_Guide/ZK_Background/Sample_of_web.xml for Servlet 3.0|Sample of web.xml for Servlet 3.0]], [[ZK_Installation_Guide/ZK_Background/Sample_of_web.xml for Servlet 2.4|Sample of web.xml for Servlet 2.4]] or  [[ZK_Installation_Guide/ZK_Background/Sample_of_web.xml_for_Servlet_2.3|Sample of web.xml for Servlet 2.3]], depending on your Web server support.
  
For older Tomcat (4.x) that supports only Servlet 2.3, please refer to [http://books.zkoss.org/wiki/ZK_Installation_Guide/Before_You_Start/Sample_of_web.xml_for_Servlet_2.3 Sample of web.xml for Servlet 2.3]
+
===Create First ZUL file===
 
+
Here is a simple zul file named '''hello.zul'''.
===Create hello.zul===
+
<source lang="xml">
For example, we can create a simple page to myZK, say, hello.zul with the following content.
 
 
  <window title="My First ZK Application" border="normal">
 
  <window title="My First ZK Application" border="normal">
 
  Hello World!
 
  Hello World!
 
  </window>
 
  </window>
 +
</source>
  
===Compress this folder===
+
===Pack your project===
壓縮myZK成為myZK.zip,rename to myZK.war
+
#Compress the '''myZK''' directory(e.g. '''myZK.zip''')
c:\>"C:\Program Files\7-Zip\7z.exe" a -tzip c:\myZK c:\myZK\*
+
#Rename '''myZK.zip''' to '''myZK.war'''
 +
#Done!!
  
=確認你的ZK.war的內容=
+
==Confirm your ZK Web Archive (WAR) file==
 +
<pre>
 
  myZK.war
 
  myZK.war
  hello.zul
+
  ¦ hello.zul
   
+
  ¦  
  └─WEB-INF
+
  - WEB-INF
     web.xml
+
     ¦ web.xml
      
+
     ¦  
     └─lib
+
     - lib
            *.jar
+
          *.jar
 +
</pre>
 +
 
 +
==Run your ZK WAR file (Deploy to Tomcat)==
 +
 
 +
To run the application in Tomcat you have to copy the myZK.war into the folder TOMCAT_DIR/webapps/.
 +
Then start the application server using TOMCAT_DIR/bin/startup.bat (or startup.sh on linux).
 +
For additional information please check the [http://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html Tomcat deployment documentation].
 +
 
 +
After Tomcat is started the application should be available under (assuming the default tomcat configuration):
  
 +
http://localhost:8080/myZK/hello.zul
  
 
=Version History=
 
=Version History=
Last Update : {{REVISIONYEAR}}/{{REVISIONMONTH}}/{{REVISIONDAY}}
+
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-
| 5.0.4
+
| &nbsp;
| 9/21/2010
+
| &nbsp;
| Created
+
| &nbsp;
 
|}
 
|}
  
 
{{ZKInstallationGuidePageFooter}}
 
{{ZKInstallationGuidePageFooter}}

Latest revision as of 03:51, 28 January 2014


DocumentationZK Installation GuideQuick StartCreate and Run Your First ZK Application Manually
Create and Run Your First ZK Application Manually



Prepare the server

Install Tomcat

First, you have to prepare a Web server. You can use any Web servers that support Java Servlet (2.3 or later). Here we introduce the installation of Tomcat. For other servers and more information, please refer to Setting up Servers.

  1. Visit Tomcat Official Site
  2. Select the correct binary distribution for your environment and download

Download ZK Libraries

ZK libraries can be downloaded from ZK Download and then save it to a proper location.

Create your first application

Here shows you how to create a web application manually without IDE or other tools.

Create Web application

ZK Web Applications use a standard directory structure defined in the Servlet specification.

When developing ZK web applications, you must follow this structure so that the application can be deployed in any J2EE compliant web servers.

All you need to do is create a web application directory with related files. J2EEWebApplication.jpg


  • Now i create one for example named myZK

Install Library Distribution

  1. Unzip zk-bin-x.x.x.zip (the x.x.x is the latest version)
  2. Copy JAR files under following list to myZK/WEB-INF/lib
    • {YOUR_ZK_UNZIP_FOLDER}/dist/lib
    • {YOUR_ZK_UNZIP_FOLDER}/dist/lib/ext
    • {YOUR_ZK_UNZIP_FOLDER}/dist/lib/zkforge

Create Deployment Descriptor(Web.xml)

web.xml is called the web application deployment descriptor. This is an XML file that defines servlets, servlet mappings, listeners, filters, welcome files etc.

The deployment descriptor is a heart of any J2EE web applications, so every web application must have a web.xml deployment descriptor directly under WEB-INF folder.

Create First ZUL file

Here is a simple zul file named hello.zul.

 <window title="My First ZK Application" border="normal">
 	Hello World!
 </window>

Pack your project

  1. Compress the myZK directory(e.g. myZK.zip)
  2. Rename myZK.zip to myZK.war
  3. Done!!

Confirm your ZK Web Archive (WAR) file

 myZK.war
 ¦  hello.zul
 ¦  
 - WEB-INF
     ¦  web.xml
     ¦  
     - lib
          *.jar

Run your ZK WAR file (Deploy to Tomcat)

To run the application in Tomcat you have to copy the myZK.war into the folder TOMCAT_DIR/webapps/. Then start the application server using TOMCAT_DIR/bin/startup.bat (or startup.sh on linux). For additional information please check the Tomcat deployment documentation.

After Tomcat is started the application should be available under (assuming the default tomcat configuration):

http://localhost:8080/myZK/hello.zul

Version History

Last Update : 2014/01/28


Version Date Content
     



Last Update : 2014/01/28

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.