Starting A Web Application Based On ZK CDI JPA and Jetty"

From Documentation
Line 16: Line 16:
  
 
=Application Stack Design=
 
=Application Stack Design=
In tradition, a web application consists 3 tiers/layers, which are: Presentation, Business and Persistence. And the component that we are using for each layer of our application can be illustrated in this graph:[[File:3_tier_archi.jpg]]
+
In tradition, a web application consists 3 tiers/layers, which are: Presentation, Logic and Persistence. In our application stack we use:
 +
* ZK as Presentation
 +
* CDI as Logic
 +
* JPA as Persistence
 +
 
 +
=== Java EE Standard===
 +
 
 
===Using light-weight Web Container===
 
===Using light-weight Web Container===
 
I use Jetty rather than a heavy duty application server because:
 
I use Jetty rather than a heavy duty application server because:
Line 25: Line 31:
 
===In Memory Persistence===
 
===In Memory Persistence===
 
I use Hibernate JPA + HSQLDB here for minimal configuration, it is very easy to swap it with other DB.
 
I use Hibernate JPA + HSQLDB here for minimal configuration, it is very easy to swap it with other DB.
 +
 +
Here is the graph of our stack:[[File:3_tier_archi.jpg]]
  
 
=Development Environment Setup=
 
=Development Environment Setup=

Revision as of 03:00, 8 August 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

DocumentationSmall Talks2012AugStarting A Web Application Based On ZK CDI JPA and Jetty
Starting A Web Application Based On ZK CDI JPA and Jetty

Author
Ian YT Tsai, Engineer, Potix Corporation
Date
Aug 06, 2012
Version
ZK 6

Introduction

Building a Java Web application is always started with a bunch of choices: Choices of which software architecture should pick, layers of architecture should define, and possible solutions or frameworks that each layer should use. And that's why we welcome a common practice; a "default stack" like "Struts+Spring+Hibernate" that we can start our project and evaluating if this stack fits our requirement or some part of it need to be swapped.

So, in this series of article, I want to propose a stack which is based on CDI (Weld), JPA (Hibernate) and ZK running on a simple web container (Jetty or Tomcat), and this could be a good start for your ZK-based application.

In the first article, I'll introduce the aiming of this stack and a little part of Java CDI technology by walking through a development Environment setup and application stack build-up.

In the second article: Practices Of Using CDI In ZK I'll introduce some programming practices to each layer and some possible solutions for some user scenarios.

Application Stack Design

In tradition, a web application consists 3 tiers/layers, which are: Presentation, Logic and Persistence. In our application stack we use:

  • ZK as Presentation
  • CDI as Logic
  • JPA as Persistence

Java EE Standard

Using light-weight Web Container

I use Jetty rather than a heavy duty application server because:

  • Fast to reboot, especially in Eclipse. You can always restart it in 5 secs.
  • Popular and friendly to everyone. A lot of people hesitate to learn CDI because though it's designed for general purpose like Spring, but it is included in Java EE specification which means you need to use an application server to play with it. Studying how to use an application server nowadays is not a big problem but the natural barrier still higher than studying a simple web container.

Weld CDI, not entire Seam

I use Weld CDI only not the entire Seam framework because I want to focus on the key features of concept injections and strategies to dealing with the consistencies between CDI and web scopes.

In Memory Persistence

I use Hibernate JPA + HSQLDB here for minimal configuration, it is very easy to swap it with other DB.

Here is the graph of our stack:File:3 tier archi.jpg

Development Environment Setup

First, let's prepare our development environment, here is the project resource host link: XXXXXX. You can download & unpack the downloadable zip file or if you are familiar with Git, you can "git clone" it to your local directory. Now, let's see the prerequisites of this project.

Eclipse IDE Preparation

Please download Eclipse 3.6 or 3.7 JavaEE Developer's package, though Eclipse already announced it's newest version "Juno"(4.2), but I haven't make sure all required plugins are functional. The required plugins list is bellow:

  1. M2Eclipse: in order to shrink the project size and manage the project well, I use Maven to manage my project, and M2Eclipse can help you import the project into your eclipse workspace much easier.
  2. Run Jetty Run: a very light weight Jetty server runner to host the runtime of your web application.

Now let's see how to configure them.

Configuration & Composition

CDI in Jetty

JNDI Settings

Weld Settings

How about Tomcat

JPA Configuration

Persistence Unit

Entity Manager in CDI

Summery

Next Article