Chapter 2: Project Structure"

From Documentation
m (correct highlight (via JWB))
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{ZKEssentialsPageHeader}}
 +
 +
 +
 +
 
= Source Code =  
 
= Source Code =  
  
  
All source codes used in this tutorial are available on [github]. Because our example application has 3 different configurations, our source code is divided into 3 branches: '''master''', '''chapter9''', and '''chapter10'''.
+
All source codes used in this book are available on [https://github.com/zkoss/zkessentials github]. As our example application has 3 different configurations, our source code is divided into 3 branches: [https://github.com/zkoss/zkessentials/tree/master '''master'''], [https://github.com/zkoss/zkessentials/tree/chapter9 '''chapter9'''], and [https://github.com/zkoss/zkessentials/tree/chapter10 '''chapter10'''].
  
[[File:Tutorial-3branches.png | center]]
+
[[File:Tutorial-ch2-3branches.png | center]]
  
The '''master''' branch contains the examples from chapter 3 to chapter 8. The '''chapter9''' branch has examples integrated with Spring and the '''chapter10'''  branch contains examples which integrate with Spring and use JPA to persist data into a database.
+
The '''master''' branch contains examples from chapter 3 to chapter 8. The '''chapter9''' branch has examples integrated with Spring and the '''chapter10'''  branch contains examples which integrate with Spring and use JPA to persist data into a database.
  
  
[[File:Tutorial-download-as-zip.png | center]]
+
[[File:Tutorial-ch2-download-zip.png | center]]
  
 
You can click the "ZIP" icon to download the current selected branch as a zip file.
 
You can click the "ZIP" icon to download the current selected branch as a zip file.
Line 15: Line 20:
 
= Run Example Application =
 
= Run Example Application =
  
After you download the source code, you will find it is a Maven<ref>[http://maven.apache.org/ Apache Maven]</ref> project with jetty plugin configured. Therefore, if you have Maven, you can run the example application with a simple command<ref>[http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin Start jetty in Maven]</ref>. Navigate to the root folder of your downloaded source code, say it's "tutorial" and type the command:
+
After you download the source code, you will find it is a Maven<ref>[http://maven.apache.org/ Apache Maven]</ref> project with jetty plugin configured. Therefore, if you have Maven, you can run the example application with a simple command<ref>[http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin Start jetty in Maven]</ref> (The maven we use is '''3.0.3'''). Navigate to the root folder of your downloaded source code, say it's "zkessentials" and type the command:
  
 
'''mvn jetty:run'''
 
'''mvn jetty:run'''
  
  
Then visit the URL ''http://localhost:8080/tutorial/'', and you should see the screen below.
+
Then visit the URL ''http://localhost:8080/essentials/'', and you should see the screen below.
  
[[File:Tutorial-index-page.png | center | 500px]]
+
[[File:Tutorial-ch2-index.png | center | 500px]]
  
 
= Project Structure=
 
= Project Structure=
  
The 2 images below show the example project structure of the example application. It's Maven default project structure, all main source are under <tt>src/main</tt>. The left image shows the Java source codes under <tt>src/main/java</tt> and the right one shows the web application content under <tt>src/main/webapp</tt>.
+
The 2 images below show the project structure of the example application. It's Maven default project structure, and all main source codes are under <code>src/main</code>. The left image shows the Java source code is under <code>src/main/java</code> and the right one shows the web application content is under <code>src/main/webapp</code>.
  
  
<div  style="width:710px;margin-left:auto;margin-right:auto;">
+
<div  style="width:630px;margin-left:auto;margin-right:auto;">
[[File:Tutorial-ch2-project-structure-java.png | 350px]]
+
[[File:Tutorial-ch2-project-structure-java.png | 389px]]
[[File:Tutorial-ch2-project-structure-webapp.png | 350px]]
+
[[File:Tutorial-ch2-project-structure-webapp.png | 229px]]
 
</div>
 
</div>
 
<div style="text-align:center;"> '''Project Structure: Java(left) and Webapp(right)'''</div>
 
<div style="text-align:center;"> '''Project Structure: Java(left) and Webapp(right)'''</div>
  
  
We name the source code packages according to each chapter and each package contains those classes used in the example of that chapter. Some common classes are separated to an independent package as they are used in multiple chapters. The classes under <tt>org.zkoss.tutorial.entity.*</tt> are entity class. We also define some business interfaces under <tt>org.zkoss.tutorial.service.*</tt> and different chapters have different implementations.
+
We name the source code packages according to each chapter and each package contains the classes used in the example of that chapter. Some common classes are separated to an independent package as they are used in multiple chapters. The classes under <code>org.zkoss.essentials.entity.*</code> are entity class. We also define some business interfaces under <code>org.zkoss.essentials.service.*</code> and different chapters have different implementations.
  
 +
For ZUL pages, we put them in an independent folder for each chapter under <code>src/main/webapp/</code>.  Under "WEB-INF" folder, '''web.xml''' contains minimal configuration to run ZK and for its detail please refer to [[ZK Installation Guide/Quick Start/Create and Run Your First ZK Application Manually| ZK Installation Guide \ Create and Run Your First ZK Application Manually]]. The "zk.xml" is optional configuration descriptor of ZK. Provide this file if you need to configure ZK differently from the default behavior. Refer to [[ZK Configuration Reference/zk.xml]] for more detail.
  
For those ZUL pages, we put them in an independent folder for each chapter under <tt>src/main/webapp/</tt>.  You will find the folder for each chapter contains a <tt>readme.txt</tt>, a brief description file which describes the goals of each chapter's example.
+
= References =
 +
 
 +
<references/>
  
  
Under "WEB-INF" folder, '''web.xml''' contains some configuration to run ZK and for its detail please refer to [[ZK Installation Guide/Quick Start/Create and Run Your First ZK Application Manually| ZK Installation Guide \ Create and Run Your First ZK Application Manually]]. The "zk.xml" is optional configuration descriptor of ZK. Provide this file if you need to configure ZK different from the default behavior. Refer to [[ZK_Configuration_Reference/zk.xml]] for complete detail.
 
  
= References =
 
  
<references/>
+
{{ZKEssentialsPageFooter}}

Latest revision as of 10:49, 19 January 2022

Stop.png This article is out of date, please refer to http://books.zkoss.org/zkessentials-book/master/ for more up to date information.



Source Code

All source codes used in this book are available on github. As our example application has 3 different configurations, our source code is divided into 3 branches: master, chapter9, and chapter10.

Tutorial-ch2-3branches.png

The master branch contains examples from chapter 3 to chapter 8. The chapter9 branch has examples integrated with Spring and the chapter10 branch contains examples which integrate with Spring and use JPA to persist data into a database.


Tutorial-ch2-download-zip.png

You can click the "ZIP" icon to download the current selected branch as a zip file.

Run Example Application

After you download the source code, you will find it is a Maven[1] project with jetty plugin configured. Therefore, if you have Maven, you can run the example application with a simple command[2] (The maven we use is 3.0.3). Navigate to the root folder of your downloaded source code, say it's "zkessentials" and type the command:

mvn jetty:run


Then visit the URL http://localhost:8080/essentials/, and you should see the screen below.

Tutorial-ch2-index.png

Project Structure

The 2 images below show the project structure of the example application. It's Maven default project structure, and all main source codes are under src/main. The left image shows the Java source code is under src/main/java and the right one shows the web application content is under src/main/webapp.


Tutorial-ch2-project-structure-java.png Tutorial-ch2-project-structure-webapp.png

Project Structure: Java(left) and Webapp(right)


We name the source code packages according to each chapter and each package contains the classes used in the example of that chapter. Some common classes are separated to an independent package as they are used in multiple chapters. The classes under org.zkoss.essentials.entity.* are entity class. We also define some business interfaces under org.zkoss.essentials.service.* and different chapters have different implementations.

For ZUL pages, we put them in an independent folder for each chapter under src/main/webapp/. Under "WEB-INF" folder, web.xml contains minimal configuration to run ZK and for its detail please refer to ZK Installation Guide \ Create and Run Your First ZK Application Manually. The "zk.xml" is optional configuration descriptor of ZK. Provide this file if you need to configure ZK differently from the default behavior. Refer to ZK Configuration Reference/zk.xml for more detail.

References




Last Update : 2022/01/19

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