The Unbearable Lightness of Java

Build web applications with Jodd

Goal to make: a skeleton for blazing fast web application, coded from scratch in just 60 minutes, 0 XML files and starting with just 1MB of jar files. Service layer: may be used and tested outside of web container, supports declarative transactions and is made of pure POJOs. Database layer: supports entity mapping, uses native sql and offers generic dao. Finally, skeleton has to be a frame for rapid further development.

This tutorial gives step-by-step instructions how to build web application using Jodd. Along it also provides some best-practices using Jodd frameworks.

This is just one way of how to build web applications with Jodd; what matters here is the concept and not the concrete values, structures or configuration used in example.

Attention: this example is not trivial one since it covers many different topics of web development. It would be good if you have some basic information about Jodd components before proceeding with the example. The subject of the example is how to configure and prepare infrastructure for development, so don't be mislead with the amount of presented information - working with Jodd is simple, but not simpler.

Here goes a short overview of each step.

Preparation

As for any web application, we need servlet container installed, such as Apache Tomcat. We also assume that database server of choice is already installed (e.g. MySql or H2 or Oracle XE or ...) and ready to use.

For this example, we need just following jars:

  • jodd-*.jar and jodd-wot-*.jar (< 800K)
  • asm-3.2.jar (< 40K)
  • slf4j-api-1.5.8 and slf4j-simple-1.5.8.jar (30K)
  • jdbc connector jar
  • servlets-2.4.jar (140K), for compilation

Next, lets choose the top architecture of our web application: we will have three separated layers: view, services and data. Service layer is not coupled with the presentation and may be executed (and tested) from the command line, if needed. Transactions are therefore declared on service layer. Data layer is written following DAO pattern. Presentation view is just preparing and calling services and parsing results back. All-in-all, nothing special, just a common three-layer web application.

Get Things Done in 60 minutes

Although presentation layer is usually not the first thing to develop, we start this example with Madvoc.

After adding the basic presentation skeleton, we can continue with the real stuff: business layer. We will organize business components using Petite.

Store with Db (20 min)

It's time for data! Let's combine the power and simplicity in one, using Db and DbOrm.

Wrap services with transactions handling code using Proxetta.

Bonuses

Control page access with Madvoc interceptors.

Different architecture type, just for fun... or real!?