// archives


This category contains 17 posts

How to integrate Spring Framework with a Struts2 application

Integrating Spring with your web application

Using Spring Framework facilitates good, extensible design by promoting interface driven programming, ease of testing through Inversion of Control and supporting various test frameworks and much more. Integrating Spring in a Struts2 based web application is a logical next step. In this post, we will integrate the Spring Framework in the Struts2 web application started in this post – Starting Struts2 web application development (using Maven2 and Eclipse)


How to add persistence to Struts2 + Spring application using JPA and Hibernate


In my previous post, How to integrate Spring Framework with a Struts2 application, I created a simple web application that used Struts2 and Spring. In this post, I am going to extend that application to add persistence logic using JPA (Java Persistence Architecture) and Hibernate.

I am assuming that you are already familiar with the technologies used in this post – Struts2, Spring and Hibernate.
My goal is to create a project that can be used to jumpstart a Struts2, Spring and Hibernate based development. This is not a detailed tutorial for these technologies.

My current development environment (at the time of developing this project) looks like this:

  • Maven: 2.2.1
  • Java: 1.6.0_20
  • Mac OS X 10.6.4
  • Struts: 2.1.8
  • Spring: 2.5.6
  • Hibernate: 3.4.0.GA


Create your own custom maven archetype

Creating custom maven archetype

Maven provides many archetypes to generate various types of project skeletons. This blog post explains how to create a custom archetype that is tailor-made for your own situation. We will create an archetype for the Struts2 application.
My current development environment includes:

  • Mac OS X 10.6.4
  • Maven 2.2.1
  • Java 1.6.0_20

Create your skeleton project

You need to have a starter project from which new archetype can be created. We can start with the Struts2 application created in the blog post Starting Struts2 web application development (using Maven2 and Eclipse) to create a custom archetype for Struts2 based applications. You can download the zipped source code for this project here.


Mac OS X Tip : Accessing /usr/local from the Finder window

Mac OS X hides many files and folders (directories) from the Finder, probably for the security reasons. Typically you don’t need to access these folders and shouldn’t mess with them.

Since I install most of my development related tools (JBoss, Apache Maven, MySQL) in /usr/local directory, sometimes I need to access /usr/local folder from the Finder window (for example, setting up Eclipse environment). This can be easily done by pressing command + shift + G (Go To Folder under Go menu) and then typing /usr/local in the popped-up dialog.


Starting Struts2 web application development (using Maven2 and Eclipse)

Before you begin

  1. Follow the blog post Starting web development with Maven and Eclipse to create a web application. This blog shows how we can extend that basic web application to add Struts2 support.
  2. This blog post assumes that you are familiar with Struts2 already. If that is not the case, this would be the good time to do so. The official Apache Struts 2 website is a good place to start. Get a free copy of the mini book Starting Struts 2. Thanks to Ian Roughley and InfoQ.com for making this great mini book available for free.


Mac OS X Tips: Switch between windows opened by the same application

When I switched to iMac from Windows, I was frustrated to find out that the Command + Tab key combination on the Apple keyboard switches between different application windows, but not between different windows opened by the same application. For example, I couldn’t use this combination to switch between multiple Firefox windows opened previously.

Of course you can use select the menu Window -> Name of the window, but I prefer to use keyboard shortcuts for a quicker navigation. It was nice to find out that the Command + ` key combination can be used to do just what I was looking for.

Mac OS X keyboard shortcuts is a good place to learn about common Mac OS X keyboard shortcuts.

Java Tip: How to use Java Timer to synchronize multiple repeating tasks

Recently I had to implement a service that involved multiple nodes in a cluster to aggregate the data for certain period of time and report it back to the central server. The central server, then aggregated results provided by all the nodes in the cluster. This required all the nodes to align properly when reporting the aggregate data to the central.

For example, if the system was configured to aggregate data for 10 minutes, each node in the cluster was expected to send the aggregate data, every 10th minute beginning at the top of the hour. In this case, the central server was expecting data from all the nodes at 10:00 am, 10:10 am, 10:20 am, 10:30 am and so on. The node started at 10:05:15 am was expected to report its aggregate data at 10:10:00 am and every 10th minutes after that (instead of 10 minutes after the node is started and every 10 minutes after that).

Starting web development with Maven and Eclipse

Before you begin

  1. Install Apache Maven 2.2.x
  2. Install Eclipse (preferably 3.5.x version or later)
  3. Install Maven plugin for Eclipse
  4. Configure Maven plugin by going to Windows -> Preferences -> Maven. Add and use your external maven installation instead of embedded version.