Friday, December 19, 2008

m2eclipse - Finally there

Yep, I did it - I gave m2eclipse another try, after reading an interview with Jason van Zyl on InfoQ several weeks ago. In it Jason stated that Sonatype is commiteing 8 full-time employees working on the m2eclipse plugin now. As it turns out, I am impressed. For me m2eclipse is finally there where I need it to be. In the past I looked at it several times but it never fit my needs back then. For my jRecruiter project, I am using a slightly modified Appfuse-based Maven pom. As in Appfuse, my project uses Maven profiles to target various different databases such as Postgres and MySql.

For my project, depending on the chosen profile, Maven will filter a file called and replaces several properties with database specific values during the processing of resources (mvn process-resources).

Here are some properties that are being filtered:


In the olden pre-m2Eclipse days, I created my Eclipse project through Maven from the command line using e.g. mvn eclipse:eclipse -P postgresql. Then in Eclipse, I had to manually include a custom file with build specific properties since Eclipse by itself can't do that type of filtering.

It worked, however, as you can imagine, this can be quite tedious, especially during the early development stage where your project's dependencies may change frequently.

But now m2eclipse is able to handle resources filtering for me from within Eclipse, which is really nice. Additionally, I can manage my dependencies using m2eclipse, and what is even better, I can visualize them as well. This is especially a live-saver when I need to figure out certain transitive dependencies.

This came in quite handy when I converted my project over to logback and SLF4J and needed to figure out all the commons-logging dependencies.

I am using m2eclipse for several weeks now, and I haven't come across any major drawbacks, yet. Granted, I haven't really dug deeply into m2eclipse's features as I primarily use only the subset discussed above, but if you use Eclipse and your project is built using Maven, please take another look at m2eclipse.

Saturday, December 6, 2008

East-Germany still alive - Der Osten lebt

I went to a "package store" the other night here in Atlanta, GA. Well, I bought a bottle of rum from Nicaragua (Flor de Caña) and saw something interesting -

The coat of arms of the former German Democratic Republic (GDR) was on the bottle's label (second seal from the left). Since I grew up in the former east, you really don't encounter its insignias since the fall of the wall that often anymore. The text on the seal is "Für hervorragende Qualität" (For superior quality)

The label also contains a the sign of the Leipzig Trade Fair, which was East-Germany's largest (Second seal from the right).
The text on the label is: "Internationale Leipziger Messe 1980".

The respective rum, by the way, is excellent.

Friday, November 28, 2008

Where is Spring 3.0M1?

Well, Thanksgiving came and went by but no Milestone 1 release of Spring 3.0 available, yet. But it looks like all open issues for M1 have been resolved. Oh well...

Wednesday, November 26, 2008

Configure Logback from your Web Application at Runtime

As mentioned in one of my earlier blog posts, I migrated my OSS project from Apache Commons Logging and Log4j to Simple Logging Facade for Java and Logback. One piece however that was left open was my web logging component. It gives you access to your log files from within the administrative area of your web application. Not only can you download the current logfile, but you can also change the log levels at runtime. Just in case some of your app's users hit an issue and you can't SSH into the server that very moment but have web access - at least you can gain an overview of the situation quickly.

Here is a screen-shot of my application's logging component:

The tables are rendered using the JMesa data grid, which works very nicely. The tables are paginated and the columns are sortable as well as filterable. Furthermore, the table is refreshed via AJAX using the jQuery JavaScript library.

On this page you can:
  • View your log files
  • Download the logfile as text file
  • View the configured loggers
  • View all available logger
  • Set logging levels for any of the available loggers
The backend is implemented using Struts 2 but you should be just as simply be able to switch the code over to Spring MVC 2.5+. There was however a minor hiccup with posting collection data back to the server using JMesa. Only the latest trunk version (As of Nov 26, 2008) allows for getting the row count for each row, which is used to map the collection data back on the server.

Although I originally used Log4j to retrieve the required logging data, the conversion over to Logback has been fairly straightforward. Here is one of the methods that interacts with logback and returns a collection of loggers:
 public static List  <ch.qos.logback.classic.logger> getLoggers(boolean showAll) {

final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
final List loggers = CollectionUtils.getArrayList();

for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if(showAll == false) {
if(log.getLevel() != null || LoggingUtil.hasAppenders(log)) {
} else {

return loggers;
Anyway if you look for something similar for your own application, you can download all the relevant source code here. Please be aware that the archive is not a full demo application but rather a couple of source files cobbled together. If you rather like to see an entire buildable demo application, just let me know.

Thursday, November 20, 2008

Book Review: jQuery in Action

jQuery in Action by Bear Bibeault and Yehuda Katz is an excellent book for learning the jQuery JavaScript library. In my opinion the book is suitable for beginners as well as advanced developers that like to explore jQuery. It is also a good reference book as it describes all the essential functionality offered by jQuery in a nicely structured manner.

I belong to the category of developers that used Prototype in the past. The funny thing is though that both libraries offer almost identical sets of functionality. You may ask why did I decide to go with jQuery?

I like its innovative way of querying for page elements and to iterated over them, allowing you to often accomplish multiple tasks with just one line of code. jQuery in Action starts out explaining those core concepts of jQuery in the first 3 chapters of the book - allowing to query for page elements using the CSS syntax, how to manipulate page elements as well as how to work with collections of elements. The book does a very good job explaining those aspects of jQuery combined with many useful examples.

What also drove me to jQuery was the fact that it has a plug-in mechanism that allows you to either use additional third party add-ons or to write your own plug-ins by still adhering to the spirit of jQuery.

In that regard it is also worth mentioning that the jQuery website is "really nice" with a ton of documentation and also providing a plugin-repository, something Prototype is lacking. Thus, for the majority of your JavaScript needs, there is now a one-stop place to get it all.

Unfortunately, the authors do not provide a comparison between both wildly popular javascript libraries Prototype and jQuery even though Bear Bibeault has been a coauthor of Prototype and Scriptaculous in Action. It would have been nice if chapter 1.1 Why jQuery detailed some pros and cons in that respect.

Generally, throughout the book, the authors encourage certain valuable patterns you should follow to write good unobtrusive JavaScript code using jQuery. I particularly like that aspect of the book as it shows you efficiently how to separate page markup from JavaScript code.

In that regard it would have been nice, though, if the authors had mentioned YSlow as another tool to analyze you page markup, which includes the recommendation to place JavaScript at the bottom of your page rather then on the top, if possible.

Anyway, there shouldn't be any need to declared the onclick attributed on page elements directly any longer. It all can be separated using JavaScript events which is well described in the book.

Speaking of handling JavaScript events, I think the authors should have further mentioned the concept of event delegation. Instead, they describe how to use the Live Query plugin in order to solve a similar issue. After reading the respective chapter, I was going to further dive into Live Query but a fellow blogger pointed out NOT to use Live Query as "it is very performance heavy" but rather to use event delegation.

I guess this is a drawback writing a book about a subject that is evolving with the speed of light.

Nevertheless, despite all my critical remarks, I think that jQuery in Action is an excellent book that will help you learn and understand jQuery. I certainly enjoyed reading the book.

Wednesday, November 19, 2008

Spring Presentation @ AJUG

Today Keith Donald gave a presentation about Spring web application development at the Atlanta Java Users Group. It has been a great presentation. The room at the Holiday Inn was packed and people were actually standing in the back (At least 100+ attendees).

The talk covered mostly the following area:
  • Spring MVC
  • Spring Javascript
  • Spring Webflow
  • Spring Faces
The presentation covered overwhelmingly 2.5 features. I wish there had been more news about the upcoming 3.0 release. Nevertheless, I asked Keith when we can get our hands on Spring 3.0 M1 and he said it will be out before Thanksgiving on November 25. And the M2 release should follow one week later. Sweet.

I have not actively developed using Spring MVC since version 2.0 and therefore the annotation support in 2.5 is realy quite nice compared to the old style. Keith showed some examples of how far you can go with annotating your action controllers as well using conventions over configuration. They way you write your controllers in 2.5 reminds me of Struts 2 actions - just better (plus the current stable release Struts 2.0.x does not have annotations support, yet.)

I wonder, especially with the 3.0 release, whether there is still any reason left to use Struts 2...but that's just my personal opinion.

Spring Javascript was another component Keith talked about. Currently part of Spring Webflow 2.0 it will eventualy become its own top level project.

It is a "lightweight abstraction over common JavaScript toolkits such as Dojo". Personally, I don't like DOJO for my typical web application development needs - it's too heavy. I rather use jQuery and DWR instead to add common AJAX functionality to my pages.

But, Spring Javascript has some interesting aspects such as gaceful degradation in case Javascript is disabled.

As Keith was getting close to the end, he only briefly talked about Spring Webflow 2.0 and Spring Faces. I wish Keith had mentioned a little bit more about the conversational state support that is supposed to be included in Spring MVC 3.0. In my current project we have the requirement to support multiple tab browsing for the same application. Thus, it would be nice to see how Spring is solving this requirement.

Nevertheless, it has been a nice informative talk and also, Keith will be back in Atlanta March 10 and 11 for the AJUG sponsored developer conference at the Cobb Galleria.

Friday, November 14, 2008

Some links regarding Spring 3.0

Can't wait to get my hands on Spring 3.0. The improvements for Spring MVC look very cool.

Plus Keith Donald presenting at the Atlanta Java Users Group next Tuesday. Stay tuned for more information from that event.

Tuesday, November 11, 2008

Migrating from JCL+Log4j to SLF4J+Logback

For my OSS project I went through the exercise of migrating from Apache Commons Logging (JCL) and Log4J to the Simple Logging Facade for Java (SLF4J) and Logback.

Logback is considered to be the successor of Log4J and is being developed by the same developer that originally developed Log4J. In return SL4J serves as a replacement for JCL.

There are already quite a few projects that use SL4J including Hibernate, Mule and Jetty to name just a few.

The migration process has been quite easy. The necessary code changes are minimal. They are virtually the same as before and the new way of declaring your loggers is:

* Logger Declaration.
private final static Logger LOGGER = LoggerFactory.getLogger(MyClass.class);

For converting your old file to logback's logback.xml equivalent, there is an online converter available. It worked quiet well, I had to do only one minor tweak for my config file.

The nice thing about SLF4J is that it provides various components that help you bridge older logging libraries such as JCL and Log4J. Therefore, even your third-party libraries that don't support SLF4J and Logback directly will ultimately use them when using those bridging components. The result: No need to have Log4J of JCL in your classpath. Nice.

The only potential headache is that if you are using Maven for your dependency management, then your direct dependencies often have transitive dependencies that include JCL.

Well, you could manually exclude the JCL depency for each of your dependencies but what a pain, even when dealing with a moderately sized project. Luckily there is a workaround available: "commons-logging version 99.0-does-not-exist". It basically downloads a fake 0 byte JCL jar. Not necessarily pretty, but hey, it works as promised.

Furthermore, I hit one more minor issue with the Jawr library: the current version is using Log4J directly. The developer of Jawr promised that in the near future they will migrate to....well...unfortunately not SL4J but rather JCL. Anyway, by using the log4j-over-slf4j bridge I was able to work around that issue, too.

Well there is one task left for my project's logging framework conversion: I have a section in my web application that allows you accessing your loggers dynamically, which also permits you to adjust log levels dynamically at run-time. So far I was using Log4J directly to implement the necessary functionality...but that is worth another blog entry another time.

Friday, October 24, 2008

Using Rinetd in Parallels on a Mac for testing your local web applications in IE

Firefox is great for web application development but due to Internet Explorers market-share, testing your application against it is mandatory. I use a Mac at home and within it I run Windows using Parallels. This works really fantastic and while my parallels instance is running, I can access my web application from within IE using my host system's IP address (I use 'Shared Networking' within Parallels).

Of course you can make accessing you local webserver a little bit more comfortable by using the Windows hosts file under %SystemRoot%\system32\drivers\etc\ to bind the IP address of my Mac instance to a more descriptive name.

However, there is still a problem with all those third party webservices such as Google Maps API and reCaptcha. When you sign up with them you create a key that works against a defined domain name. Nevertheless, for testing you can typically also use http://localhost/ etc. which is nice as I only need one key for both deployment and local testing.

Well, for accessing your web application from within parallels via localhost, rinetd works like a charm. Rinetd does port redirection and it is a tiny little command line utility that runs as a daemon. Originally from the Linux world there is also a Windows port available.

After downloading, all you have to do is to create/edit the config file rinetd.conf. In it I have only one line: 8080 8080

This line redirects all local calls on port 8080 to port 8080 of the ip address

Saturday, October 18, 2008

Incorporating reCAPTCHA into your Struts 2 + Spring Application

Who thought that that CAPTCHA implementations are only good for preventing spam? It turns out that the reCAPTCHA project from Carnegie Mellon University also does some common good. Developed by the same people that coined the term CAPTCHA, the project is also being used to help digitizing old books and publications (Including my favorite US Newspaper). The process is further explained here.

In addition to that it is a slick CAPCHA implementation as well, that you can incorporate freely into your web applications. There are APIs available for various languages including Java, Ruby and Python.

For my Struts 2 + Spring project I am using reCAPTCHA for the user registration page. The user fills out the registration but before s(he) submits the form a reCAPCHA form field has to be filled out, which means recognizing 2 words that are part of an image and retyping those two words into a form field. Upon form submission, code in my Struts 2 action calls the reCAPCHA Java API and validates the two words that were previously entered by the user.

Setting everything up has been easy and involves the following steps:
  • Signup for a reCAPTCHA account and generate the necessary keys for your site (similar to setting up Google Maps)
  • Add the recaptcha4j library to your project
  • Add some Javascript code to your JSP
  • Define the main recaptcha4j bean in your Spring ApplicationContext.xml file
  • Configure your Struts 2 Actions to process and validate the reCAPCHA form data
In your applicationContext.xml file you need to add the following bean definition:

<bean id="reCaptcha" class="net.tanesha.recaptcha.ReCaptchaImpl">
<property name="privateKey" value="your private key"/>
<property name="publicKey" value="your public key"/>
<property name="recaptchaServer" value=""/>
<!-- For SSL use:
<property name="recaptchaServer" value=""/> -->
<property name="includeNoscript" value="false"/>

In your jsp:

Setup your Struts 2 action to process two form parameters:

  1. recaptcha_challenge_field

  2. recaptcha_response_field

Then in your actual action code you validate those 2 token by calling:

public class SignupAction {
private User user;

private String recaptcha_challenge_field;
private String recaptcha_response_field;
private @Autowired ReCaptcha reCaptcha;

public String execute() {

ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(

if (!reCaptchaResponse.isValid()) {
addActionError("Not a good CAPTCHA.");
return INPUT;

...process the user registration form etc.

return SUCCESS;


...your setters

That's it. These should be all the basic steps necessary to get you going.

Here are some further resources:

Thursday, October 16, 2008

First Visit to the Atlanta Flash and Flex User Group

I finally made it to a meeting of the Atlanta Flash and Flex User Group. Ryan Swanson gave a great presentation on the Flex Data Services Framework, which was quite interesting. He also also showed us his project Regular Expression Explorer. Written in Flex, it looks like a really slick application.

Below are a few mostly Flex related links that might be of interest:

Not Flex specific, but if you need to satisfy your Mashup needs:

Several interesting Flex blogs:

A ton of presentations:

Flex Libraries:

Wednesday, October 8, 2008

Hibernate - Derived Properties

The other day I used for the first time derived properties in Hibernate. What this means is that instead of mapping a property of your POJO class to a database column, your property is computed dynamically by doing an additional sub-select.

It is briefly discussed in chapter 5.1.11. of the Hibernate documentation. It is probably not a feature that will need often, however it can be a life/time-safer if you need it. It worked great for me.

Monday, October 6, 2008

jQuery - Creating Modal Dialogs

I am still working my way through the jQuery in Action book and I still need to write a review on it...soon....
Well, this weekend I was checking out several jQuery plugins - In my home project I needed to replace a few old-school/legacy JavaScript confirmation boxes with something more stylish looking. While jQuery by itself is very nice, its plugin mechanism and consequently its plugin repository is simply impressive. There is almost too much choice ;-) Anyway, there were several plugins for creating modal dialogs. I finally settled on SimpleModal - So far it worked quite well and the documentation is helpful, too.

The next plugin I have to look at is Live Query. I use a few Ajax driven data grids that return DOM nodes to which I would like to attach events. Live Query watches out for those node changes and applies some magic to make it work.

Friday, September 26, 2008

Creating Excel Files with POI - Issue

HSSF (Horrible SpreadSheet Format) is a great library for creating Excel spread-sheets using Java. It is part of the larger Apache POI project. Yesterday I hit an interesting issue while creating an Excel file with a modestly large collection of elements.

The Excel file was generated fine by HSSF but when opening it, Excel greeted me with the following message:

"some text formatting may have changed in this file because the maximum number of fonts was exceeded"

As it turns out, Excel only allows for a limited amount of styles/fonts to be used. Thus, the good advice when dealing with Excel files is to reuse styles and fonts wherever possible. It also results in substantially smaller Excel files. I was able, in my little example, to reduce the file-size from 54kb to 17kb, just by refactoring my usage of styles.

On last interesting observation: Once you hit that popup error in Excel, it does not simply suffice to close the Excel file, but you must restart Excel in order for the message not to popup again.

Friday, September 12, 2008

Flex and Maven First Steps

I finally decided to take the plunge and started learning Flex last night. First I wanted to setup my environment. As I don't have a Flex Builder License (My Evaluation License Expired before I had a chance to actually use it...arrgh...) I started creating a simple build environment that works with a plain Eclipse setup.

As far as I see there are 2 options out there:

After some Googling the there seemed to be a preference for flex-mojos. So I decided to go with it.

Getting my first hello-world compile using flex-mojos was a bit tricky. The issue is that flex-mojos is under heavy development and seems to change a bit. E.g. the location of their Subversion repository and Maven repository changed which however is not necessarily reflected in their examples. Nevertheless there is a very helpful blog and a useful wiki available.

In order to keep up with the project, I decided to also check-out the latest flex-mojo trunk from Subversion and build it locally. Well, it turns out that my local Maven version on my MacBook Pro was not up-to-date but finally I got everything running.

Thus, after some fiddling around I got my first Maven-based Flex-Hello-World running.

In my next post I blog about some further progress and also some of the configuration that was necessary.

As it got really late last night I came across good read about building Flex applications using Maven and Flex-mojos:

Upgrading Maven on Apple's Leopard

Today on my MacBook Pro I needed to upgrade the pre-installed Maven version 2.0.6 to the latest Maven version 2.0.9.

This gave me a good reason to install MacPorts. The took a little bit of time, especially since as a pre-requisite I also needed to install Apple's Xcode which comes along as a hefty 1GB download.

Once it was downloaded and installed, I installed MacPorts. For some reason after the MacPorts installation successfully finished, executing sudo port -v selfupdate did not work. The port command was not found... Well, it turns out that I needed to add the path to my .profile which is located in the home directory:
  • export PATH=/opt/local/bin:/opt/local/sbin:$PATH
  • export MANPATH=/opt/local/share/man:$MANPATH
That did the trick.

Lastly, all I needed to do in order to install the latest Maven version was to execute:

sudo port install maven2

Maven 2.0.9 was immediately available thereafter:

mvn -v

Wednesday, September 10, 2008

Effective Java @ Parleys - Presentation

I loved reading Effective Java Second Edition by Joshua Bloch - At Parleys they have a presentation by Joshua Bloch on some of the issues discussed in the book. It is really a great presentation and I can only highly recommended it (e.g. for understanding PECS when dealing with generics (producer extends, consumer super)).

Tuesday, September 9, 2008

jpwgen - Password Generator for Java

If you ever have the requirement to auto-generate passwords that must meet certain security guidelines such as having at least one number, a special character etc. then take a look at jpwgen. It is written in Java and is based on pwgen (unix).

What is nice about it is that you can use it both as a command line program and/or as a library within your applications.

By the way, if you need a GUI tool for Windows to generate passwords, check out pwgen-win

Monday, September 8, 2008

A Life-Changing Event...

On August 27, 2008 our daughter Leah Annarose was born. As I am posting this, she is already almost 2 weeks old.

Time is racing by, to say the least - The last 2 weeks were really amazing and having a child is a truly new experience; a great one.

For the years to come, it's now time to be a dad.

Thursday, August 21, 2008

Adobe Flex in Atlanta

Our yesterday's AJUG meeting has been awesome. James Ward delivered a great presentation on Adobe Flex and the room was packed (100+ attendees). I just hope Sun can still pull off Java FX and make it truly rock solid because Adobe Flex looks cool and very polished to say the least. Also the integration with Java backends also looked very nice (Adobe's BlazeDS or Granite Data Services). One of the demo's James showed can be found here.

Additionally, here in Atlanta there are more and more Flex projects going on...I wonder if it starts reaching a tipping point.

Finally, I think I need to check out the Atlanta Flash and Flex User Group, especially since it is just around the corner from where I live :-)

Wednesday, August 20, 2008

AJUG DevCon 2009 - Planning

At the Atlanta Java User Group, we are in the middle of planing the 2009 Java DevCon conference. As of now the conference will take place from March 10-11 in Atlanta. We are planning for around 400 attendees. Thus, over the coming couple of weeks we need to finalize our list of speakers. If you're interested in presenting at DevCon feel to contact AJUG at info at ajug dot org or you can also contact me directly at gunnar at hillert dot com.

Tuesday, August 5, 2008

Spring does not like IBM's Java Runtime Environment

I had to learn the hard way that Java JVMs from from different vendors may behave slightly differently - As it turn out, one of my little apps was running fine on Sun's JVM but was causing a weird NPE on IBM's Java Runtime Environment (1.6 64bit)

As it turns out, this was already a reported issue in Spring's Jira. Even better - it was already fixed and after updating Spring from 2.5.3 to 2.5.5 everything is running smoothly again.

Saturday, July 26, 2008

Struts2, JFreeChart - Transparent Charts

For my Struts 2 application I needed to create a chart using
that has a transparent background (rendered as png). Well, I thought
this would be trivial to do as Struts 2 ships with a
for it...

I created a simple action that creates a chart:

     public final String execute() throws Exception {

final DefaultCategoryDataset categorydataset = new DefaultCategoryDataset();

this.chart = ChartFactory.createLineChart("MyTitle",
"categoryLabel", "valueLabel", categorydataset,
PlotOrientation.VERTICAL, true, true, false);
chart.setBackgroundPaint(new Color(255,255,255,0));

return SUCCESS;

In my Struts XML file I put this:

<br /><action name="createChart"
class="com.hillert.sandbox.ChartAction"><br /> <result
name="success" type="chart"><br /> <param name="width">200</param><br /> <param
name="height">150</param><br /> </result><br /></action>

Well, the result is that my chart gets generated and rendered but
without transparency.

After asking the internet's oracle for guidance, Google returns a fews
results, e.g

that indicate that JFreeChart by default does not generate Alpha
Transparency for Pngs.

The solution however lies in customizing the jFreeChart Struts plugin.
In it's shipped version the plugin is calling:

ChartUtilities.writeChartAsPNG(os, chart, width, height);

For transparency you need to use the
method call

. Simply change the method call above to:

ChartUtilities.writeChartAsPNG(os, chart, width, height, true, 0);

As a result aplha transparency is enabled and my chart is generated with
a transparent background.

Just for completeness, here is my action configuration using the
customized jFreeChart plugin:

<package name="chart"
extends="jfreechart-default" namespace="/chart"><br /><result-types><br /><result-type
name="customChart" class="org.jrecruiter.web.CustomChartResult"><br /></result-type><br /><br /><action
name="createChart" class="com.hillert.sandbox.ChartAction"><br /><result
name="success" type="customChart"><br /> <param name="width">200</param><br /> <param
name="height">150</param><br /></result><br /></action></result-types></package>

Tuesday, July 1, 2008

Book Review: Effective Java, Second Edition

Effective Java, Second Edition by Joshua Bloch is certainly the best Java book I have read in a long time. As a disclaimer, I never read the first edition and I am thus unable to compare the two editions. Effective Java, Second Edition is a mostly easy and fun read providing you with many insights and best practices on how to use Java effectively. It certainly is not a book for the beginner just starting out learning Java. For that purpose you may want to take a look at Thinking in Java by Bruce Eckel instead. Nevertheless, Effective Java would serve as an excellent follow-up.

In Effective Java, Joshua Bloch does a great job describing best practices that you as developer will find useful on a daily basis. For example, I really found his description of the builder pattern (Item 2, page 11) quite interesting. Another Item that fascinated me, was Item 15 (page 73) - "Minimize mutability". Both items are part of a broader theme throughout the book that promotes creating code that is as immutable as possible. In that regard, reading the book will enable you to simply write better and safer code. The book also leads the way towards promoting functional programming techniques which will come in quite handily when developing multithreaded applications. Therefore, as a next book I may recommend reading Java Concurrency in Practice by Brian Goetz.

Even for the experienced Java developer, Effective Java contains quite a few little eye openers. I for example was previously unaware of how static factory methods can simplify the creation of parameterized type instances using "type inference". This example is described on page 9 (Item 1). In the past I had always used something like this:

List users = new ArrayList();

But by using a static factory method you can do:

List users = Helper.newArrayList();

I thought that this was a pretty nifty example that may help making code a bit cleaner. What I also very much liked about Effective Java was that Joshua points out certain short-comings of the Java language itself and its APIs whenever applicable. For example, page 64 describes the inconsistent behavior between BigDecimal's 'equals' method and its 'compareTo' method, and in item 41 (page 194) Joshua details the shortcomings of the List interface when using Autoboxing.

While the vast majority of the book was very easy to read and to understand, I found that the chapter about bounded wildcards using generics (item 28) was a little difficult to grasp and I wished it were a bit more extensive. On the other side, the provided mnemonic is quite helpful: PECS - Producer-extends, Consumer-super.

Overall, I highly recommend Effective Java, Second Edition which will continue to serve me, and likely you too, as an excellent reference resource.

Wednesday, June 18, 2008

TED - Ideas and Inspirations

On the Java Posse they mentioned a presentation by Jill Bolte, a brain researcher, about her experiences having suffered a stroke - It was an amazing presentation! I also have to explore more of TED. There seems to be a ton of good stuff...

Wednesday, June 4, 2008

NFJS Atlanta 2008 Report

I just realized that I started writing a blog entry about attending the No Fluff Just Stuff conference here in Atlanta (May 16-18) - but never finished it...Oh well - Anyway, it was a great conference and the provided backpack will certainly serve me well :-)

Here are the sessions I attended:

  1. Developing Rich Internet Applications by Richard Monson-Haefel
  2. Java Memory, Performance and the Garbage Collector by Ken Sipe
  3. Architecture and Scaling by Ken Sipe
  1. Tactical Continuous Integration with Hudson by Andrew Glover
  2. SOA's Challenges by Ken Sipe
  3. Dojo: Getting Started by Nathaniel Schutta
  4. Configuring Spring with Annotations by Mark Fisher
  1. Enterprise Integration Patterns with Spring by Mark Fisher Part I
  2. Enterprise Integration Patterns with Spring by Mark Fisher Part II
  3. Introduction to Tapestry 5 by Howard Lewis Ship
  4. Pragmatic Patterns with Tapestry 5 IoC by Howard Lewis Ship
For me the best presentation was the second part of the Enterprise Integration Patterns talk by Mark Fisher. It was basically all about Spring Integration - This project looks way cool! It basically allows to componentize your application, similar to how you work with JMS. But Spring Integration is working on a lower level. It also has features that are typically found in ESBs such as adapters for mail, JMS, FTP etc. Mark Fisher hinted that in the future Spring Integration may also evolve into a workflow solution.

In terms of speakers - Ken Sipe was simply terrific. I did not expect an overly exciting presentation when listening to "Java Memory, Performance and the Garbage Collector" but I was very impressed. Great talk and very informative.

Lastly it is always nice to listen to Howard Lewis Ship - Tapestry looks good and I really need to play with it at some point - if only the day had 48 hours...

Can't wait for the next conference - Jay, job well done.

Wednesday, May 28, 2008

Addicted to YSlow and what Jawr can do to help

At the No Fluff Just Stuff (NFJS) conference I attended 2 weeks ago, somebody mentioned YSlow, which is a tool for analyzing websites in regards to performance and is a plugin for Firebug. Hence, this week I spent some time using it and fixing the issues YSlow found on my project.

It is really nice and almost addictive...YSlow grades the performance of your website in a number of categories. There is a good site at yahoo explaining those categories called: "Best Practices for Speeding Up Your Web Site".

For example, you should always put CSS at the top of your web pages and JavaScript files should be at the bottom. While this is easy to fix, the recommendation to reduce HTTP request is a bit trickier to fix.

Well, let's assume you implemented a typical Web 2.0 website using a few Javascript libraries such as Prototype, Scriptaculous as well as your own Javascript files. Furthermore, you broke your CSS into multiple files because otherwise you would simply lose control over it entirely.

That of course causes a lot of HTTP requests when loading the files and thus leads to a degradation of your website's performance.

But luckily if you write Java based web applications there is a really cool library out there called Jawr that let's you bundle up (combine) your Javascript and CSS files. Not only that, Jawr also minifies your Javascript and CSS files plus it is able to GZip the files as well. Jawr also provides a nice quickstart tutorial and lastly Jawr also has a tutorial that explains how to use it with the big JavaScript libraries such as jQuery, Prototype, Scriptaculous and Yahoo! UI library.

Wednesday, May 21, 2008

RSS Feed Aggregators

For the Atlanta Java User Group I have been looking into providing an RSS feed aggregation service for blogs of AJUG members. Since AJUG is running its own server, I wanted to provide a server-based solution. Interestingly, it seems the choices are rather slim when looking for something that is OSS. Pratik mentioned groovyblogs. It looks interesting, got it running very quickly, but I saw one too many stacktraces when clicking through the application. Maybe just bad luck...Once I find the time to dive deeper into Groovy and Grails, I may return to groovyblogs, though. The source code is available here.

Barry Hawkins pointed me to Planet, a Python-based feed aggregator. To see it in action, take a look at Well, after looking at it, I found Planet Venus its successor. Compared to the original Planet, Planet Venus actually has some documentation (I like documentation!) and a fairly active mailing list. Furthermore, is using Planet Venus. You can find it at There is also blog entry by Sam Ruby that provides a little more background information regarding Planet Venus.

Anyway, the actual installation has been trivial - it is basically just a command line script, that parses RSS feeds, applies a template and than spits out html pages. Thus, adding the script's execution to your crontab is all that is needed to feed your aggregator with new data.

Monday, May 19, 2008

Spring Security 2.0

For my home project, I updated ACEGI security to Spring Security 2.0.1. My experience was similar to Matt Raible's - positive. I was able to cut down the XML configuration quite substantially. At the end only 49 lines remained (Including XML namespace declarations).

The migration was very easy except for 2 smaller issues (See further below). First, I updated web.xml to rename the security filter to Spring Security's one:





Also, since I am using my own "user service" to pull users and roles from the database, I had to rename a few imports in my classes to reflect the package names of Spring Security 2.0.

The biggest configuration change was updating the bean definition in my context configuration file which contains all the necessary XML to wire all the beans together. Spring Security 2.0 is now providing its own XML Namespaces, which drastically simplifies configuration.

Thsu, here is the final application context configuration file for Spring Security 2.0 as used by my project:

As mentioned above, I encountered two smaller issues. First, I am using the Jasypt library which I am using for digesting passwords. It provides a password encoder that plugs into ACEGI security. Unfortunately, it has not yet been updated to also work in conjunction of Spring Security 2.0. The aforementioned implemented password still uses the old package structure. Thanks to open source this is an easy fix :-)

Thus, I checked out Jasypt into my Eclipse Ide, updated the package reference and the pom to pull in the Spring Security 2.0 jars. I also created a ticked on the Jasypt project website and submitted a patch with the changes. Let's see whether it will find its way into the prokject soon.

My second problem had to do with the rolePrefix of Spring Security. Spring Security by default pre-fixes roles names with "ROLE_". Since my project does not use prefixes for role names I had created rolevoter bean that set the rolePrefix property.

Interestingly you can't do this configuration using namespaces. With the current version you need to fall back to the traditional bean configuration support which involves creating 3 additional beans:

  • roleVoter

  • accessDecisionManager

  • authenticatedVoter
There is a little more information available on the Spring forums about this. Hopefully this maybe be simplified in the future - thus, I opened a ticket for this on the Spring Jira.

Wednesday, May 14, 2008

If Tomcat is Running out of Memory...

If your Tomcat is running out of memory, take a look at the following issue posted by Atlassian. It affects basically all Tomcat versions including Tomcat 6.

The fix is to set the following JVM parameter:


And, just for completeness - if you need to specifiy JVM parameters for Tomcat, create a file called in your Tomcat's bin directory.



-Xms512m -Xmx512m \
-XX:PermSize=128m -XX:MaxPermSize=256m \
-server \
-Djava.awt.headless=true \


Tomcat will pick up the file automatically when it starts up. Regarding Permspace issues, there was a good discussion about it over at Matt Raible's Blog.

Wednesday, April 30, 2008

Lightbox gone crazy...

If you think there are too many Java web-frameworks out there - check out the market for JavaScript Lightbox libraries:

Tuesday, April 22, 2008

Learning Spanish

I started reading my second Spanish book: Pueblos del Caribe y la Amazonia. The book describes the life and customs of the indigenous people in pre-hispanic times. So far it seems to be a relatively easy informative read and I like to learn more about Latin-American history anyway. My next Spanish book is already waiting - Diarios de Motocicleta...Good ol' Che. I have been taking Spanish classes for the last one and a half years and finally things start making more and more sense. 

Which reminds me - my last level (12) at the Latin American Association here in Atlanta starts this week.

Monday, April 21, 2008

Converting Daos from Hibernate to JPA

Over the weekend I converted the Daos of my pet project jRecruiter from Hibernate to the Java Persistence API (JPA) using Hibernate as persistence provider. The project is using the latest Spring version (2.5.3) and I also incorporated Spring's latest annotation features. This allowed me to remove all the Dao-related Spring bean declarations in my context.xml file. The actual conversion from pure Hibernate to JPA was quite straight forward. I was struggling a bit with the Spring configuration of the entityManagerFactory but got it to work eventually.

Here is my Spring context file with the JPA setup.

true 'Y', false 'N'

The modifications to the daos itself were rather modest. One difference I noticed is that executing a query using query.getSingleResult(); throws a NoResultException. I prefer returning null - therefore I had to do the following:

try {
user = (User) query.getSingleResult();
} catch(NoResultException e) {
user = null;

Also, the Dao classes are annotated with @Repository e.g.:

public class UserDaoJpa extends GenericDaoJpa<>
implements UserDao {

Also, I use some of the new Spring features that allow me to get rid of quite a bit of XML:

Using context:component-scan Spring will auto-detect my daos and registered them with the context without any XML necessary. I think this is kind of neat especially for smaller projects.

Lastly, in case you need to access Hibernatenate's SessionFactory directly:

Session session = (Session)entityManager.getDelegate();

Friday, April 18, 2008

Save the Sharks!

I just watched Sharkwater. In my opinion this is the best documentary I have seen in a while. It shows some amazing underwater footage. Seeing the hammerhead sharks congregate near Cocos Island is truly impressive. Nevertheless, the movie delivers an important message: Sharks are not the dangerous animals as you might see on the mass media. More people are killed by vending machines every year than by sharks. 
In fact, sharks are an important keystone species without which many marine ecosystems may collapse. For example research indicates that the ongoing removal of sharks contributes to the decline of coral reefs. I am a certified diver and would like to continue enjoying the mystique and beauty of the world's coral reefs.


Sharks are are literally in danger of being wiped off the map by overfishing (shark finning) and habitat destruction – Every year 50-100 million sharks are killed. The documentary also explains and shows the effects of longline fishing, a really nasty practice.
Thus, even if you don't love sharks, they are critical for the marine environment and need to be protected. We cannot afford loosing them. Please spread the word! 

Wednesday, April 16, 2008

Using Annotations in Spring 2.5 to the Extreme

For the past couple of years I have been using Spring in almost all of my projects. It has been mostly a great experience. However, there was always a lot of XML involved in order to wire all those beans together. This held true also for Hibernate as well as other frameworks. Did I mention Acegi Security?...

Well, then the community decided that annotations were an awesome way of cutting down on all this configuration clutter. Paired with the concept of sensible defaults brought over from the Rails community, live started to get easier. Guice introduced annotations-based dependency injection (DI), which has also been adopted by Spring. Thus, if you use JPA or Hibernate Annotations combined with all the whiz-bang offered by Spring you can virtually eliminate all your XML glue-code.

Well, with Spring 2.5 you can take DI to the extreme by also eliminating all your dependency-setters. For example, in your service methods you can annotate your private data access object variable declarations with annotations (e.g. @Autowired) that will inject the necessary dependencies for you. No need to declare public setters.

While this sounded kind of exciting and works well, I started scratching my head when dealing with unit-testing. How do I mock my service class' dao objects when there are neither public setters nor respective constructors?

For this issue Spring comes to the rescue with the following helper class, which provides helper methods for setting non-public variables or setters:


Here is an example using EasyMock for creating a partial mock object:

final User Dao userDao = EasyMock.createStrictMock(UserDao.class);
ReflectionTestUtils.setField(userService, "userDao", userDao, UserDao.class);

And in my Service class I declare:

/** User Dao. */
private @Autowired UserDao userDao;

For more information regarding the new features in Spring 2.5 check out this article at InfoQ as well as this blog entry.

This very streamlined way of doing dependency injection without setters is very interesting, but to me it poses the following question:

Is this usage of annotations pushing the envelope a little too far?

It certainly binds you code more to the underlying framework (Spring) but on the other hand it feels kind of nice and works well. In my understanding this might be a really productive way of implementing smaller projects but it might be problematic for bigger ones...

Saturday, April 12, 2008

AJUG's Server found a new Home

I moved the server of the Atlanta Java User Group from the Midtown Atlanta to its new location in Suwanee, Ga. For many years the server was hosted by a data center facility in Midtown but last weekend we got the surprising news that due to policy changes we had to move out. Therefore, Burr Sutter, our president, sent out a message to our community asking for help. Thanks to many, many responses from AJUG's members, we had a few options by the middle of the week. At the end we chose 4t Networks who offered use sponsored hosting. 

By the way, the data-center in Suwanee, Ga. The data-center is really quite impressive - you can find more information here

Wednesday, April 9, 2008

Social Networking and the Atlanta Java User Group

The Atlanta Java User Group has certainly a very healthy membership basis. We have 1400 subscribers to our announcement mailing list as well as 600 subscribers to the general membership mailing list. 11 days ago I created a group on LinkedIn for the Atlanta Java User Group in order to increase the visibility of the group. Previously, I had already become a member of the Java Posse LinkedIn Group and wanted to provide the same exposure to the Atlanta Java User Group. It has been quite exciting to see the rapid adoption rate. Within 48 hours we had 100 sign-ups and yesterday we hit 155 subscribers. It seems that social networking is becoming an essential tool to IT professionals these days. 

Sunday, March 16, 2008

Changing Company without Changing the Job

Starting this week I am working for Engauge instead of Spunlogic. Well, it is still the same job but Spunlogic joins Engauge and thus becomes part of it. This is certainly something you don't experience every day plus we got a nice welcome package :-)

AJUG March Meeting - JPA with Spring 2.5

Today I finished preparing for the Atlanta Java User Group's March meeting next Tuesday (Updating the website/preparing the mailing list announcement) .

The topic is: Enterprise JPA with Spring 2.5. You can find more details here. Pratik Patel will give the presentation and I am really looking forward to it. Thanks Pratik!

Tuesday, March 11, 2008

Highlighting Source Code in HTML

I came a project on Google Code that is particularly interesting for us software devs when writing our blog entries that often encompass code snippets. Therefore, take a look at SyntaxHighlighter. SyntaxHighlighter formats your source code by using JavaScript, only, and supports many different language including Java, Ruby and Python.

Monday, March 10, 2008

Toilets for America

Although the current political situation here in the US is crappy, to say it bluntly, this blog entry is not about politics but rather about how you can save a lot of water when using the right toilet.

Growing up in Germany, I am accustomed to having toilets with instant flush-stop which are very effective. As far as I believe and read on various internet sites the situation is quite similar across other European countries, Japan, Israel, Australia etc.

In the US the situation is improving but unfortunately still lacking. My wife and I live in a twenty year-old town-home in Atlanta, Ga, that had the original toilets still in place. This means the toilets were using approximately 3.5 gallons (13.2 liters) of water per flush. Not good.

Since last year residents of Georgia have been enduring a total outdoor watering ban, and I finally decided it is time to start doing something. And thus I spent some time investigating the options I have in order to save more water by replacing my toilets.

Currently, federal law mandates toilets that are using 1.6 gallons (6.1 liters) of water per flush. This is much better than my old toilets, but we can do better. There is a federal label for water-saving products called EPA WaterSense. Products with this label are required to use no more than 1.3gallons per flush. Cool, but can I do even better?

The best - To reduce water consumption even further, you can choose dual-flush toilets that reduce water consumption by an additional 25%. Those toilets have basically 2 buttons. One for the 'big stuff' and one for 'liquids' using only 0.8gallons (3 liters) of water per flush.

Once I decided to go for the best available option, provided the price be acceptable, the tough part started. Which manufacture/model do I choose as well as where to buy?

First of all, the 2 big home improvement stores, Lowe's and Home Depot, were quite a bust. Their selection of EPA Watersense certified toilets is quite limited. Taking it to the next step and asking for dual flush toilets is like asking for the moon. This is very disappointing for a metropolitan area of 4.5 million in a severe drought.

Anyway, in my opinion, the best product I was able to come up with is a company called Caroma and they provide a list of their local suppliers on their website. Luckily they have suppliers that are local to Atlanta.

The model I chose is the Sydney 305 Elongated and thus I purchased 3 toilets from ecoTransitions Inc. They were extremely helpful and home-delivered.

Installation was quite straightforward, considering the fact that this has been my first installation ever. Finally, I must say they work great!!

Wednesday, February 20, 2008


Sometimes you just have the requirement to sort java collections...In that case the BeanComparator from Jakarta Commons is quite handy:

ArrayList sortFields = new ArrayList();
sortFields.add(new BeanComparator("lastName"));
sortFields.add(new BeanComparator("firstName"));
ComparatorChain multiSort = new ComparatorChain(sortFields);

Friday, February 15, 2008

Email Aliases on a Linux Box

It is actually dead-simple:

vi /etc/aliases

Add your aliases like:


(Multiple email addresses are separated using a comma)

Afterwards run the command newaliases so that the made changes take effect.

Thus, if your server's domain is, then any email sent to goes to

That's it.

Thursday, January 31, 2008

Minor JAXB gotcha with Java 6

I hit a small issue today with JAXB and Java 6. It turns out that I was using JAXB 2.1 but Java 6 "prefers" JAXB 2.0. I found some helpful information here.

Tuesday, January 22, 2008

Let Hibernate generate pluralized table names

On my little home project I am using annotations-based Hibernate persistence. As a personal preference I like table names to be pluralized (Call it Rails-inspired). Unfortunately, Hibernate does not provide any support for such a feature and therefore I always ended up specifying the table columns explicitly:

public class Job implements Serializable {

However, there are hooks to change the default Hibernate NamingStrategy implementation. This means, if you don't provide the @Table annotation then the class name maps directly to the table name.

In fact Hibernate comes with 2 naming strategy implementations out of the box:

Well, on I came across the Inflector project, which generates the plural of provided nouns. Using it could not be simpler:

String result = Noun.pluralOf(“cat”) ; // = cats

As a result of that find, I created my own class ImprovedPluralizedNamingStrategy which uses ImprovedNamingStrategy as a base. I refactored the contained method classToTableName() so that it returns a pluralized version of the class name.

Also, if you like to know more on how to configure Hibernate naming strategies when using Spring, check out this blog.

What I have done is certainly not production ready but it shows that adding your custom naming strategy to Hibernate is fairly easy to accomplish and helps reducing annotation clutter in my classes.

Thursday, January 17, 2008

Learning Scala

Since the Java Posse has been talking about Scala a lot lately (E.g. episode 155), I felt compelled taking a closer look at Scala myself the last couple of days. Scala is a functional programming language that runs on top of the Java Virtual Machine (JVM). While it has its own interesting syntax-twists it is certainly easier to grasp for Java developers than for example Ruby (Purely from a syntax perspective). You can find more information on the Scala website.

I have not done much, yet. I downloaded it, installed the Eclipse plug-in and went through a good portion of the official Scala Tutorial. I also read “First Steps to Scala” at

Tuesday, January 15, 2008

Aprender español en Atlanta

Hoy empecé mi próxima clase en la Asociación Latinoamericana aquí en Atlanta. Actualmente estoy en nivel 10. ¡Solamente 2 más niveles!

Friday, January 11, 2008

Java and the Brazilian Healthcare System

One thing I forgot to mention in my previous blog entry about the Sun Tech Days in Atlanta was the Q and A session with James Gosling. One of the questions was: In his opinion what is the most impressive/interesting Java application he came across and James started talking about the Brazilian Healthcare system, which is running a Java based platform.

Following James, all you need in Brazil is a healthcare card. The whole system is paperless. For example if your doctor gives you a prescription you still only need your healthcare care when showing up at the pharmacy. When going to a different doctor, (s)he just looks up your records in the system.

The system also handles some interesting requirements: names and addresses are optional. For example there are people living the in Amazon forest with changing locations. Also, there are indigenous people that consider a person’s name personal and thus won’t share it with their doctors.

Some quick searching using Google produced the following interesting looking links:

I may spend some time over the weekend reading those articles. Maybe we can implement a similar system in the US???

Sun Tech Days Atlanta

It has been a long day. Nevertheless a really good one – We had Sun Tech Days here on Atlanta and I got the chance to attend the conference today. The whole event had started at 9am and I was able to leave shortly after 8pm. This was a great event and the best thing – it was completely free (including breakfast, lunch, cake, beer/wine and of course T-shirts)

The presentations were really good for the most part. The day started with the keynote speech given by Jeet Kaul speaking about the latest developments at Sun such as Glassfish, Netbeans 6 and JavaFX. Also, if you think the Nintendo Wii is too boring, check out Project Sun Spot.

Also, I need to check out Open Solaris – They showed, how you can natively run various VMs in it (such as Windows, Linux etc.). Another cool feature is ZFS

The first presentation I attended was “A Rich Application Platform: Java FX”. It looks promising not just for writing Flash replacement web applications but also for simplifying Swing development. However there are still a few missing pieces, the biggest being the lack of a modular JVM. However SUN said that the modular JVM may be released by May/June 2008. Lastly the speaker talked about the Java FX platform which is basically an operating system for mobile phones and using JavaFX for the UI.

I wonder how it compares to Google’s Android.

Next I went to the SOA and OpenESB presentation which talked about BPEL, OpenESB and JBI. OpenESB’s tool support using Netbeans 6 looked really slick. I have to check that one out. The BPEL designer actually looked quite a bit better than JBoss’ offering (visually)

The I went to the “Filthy Rich Clients” presentation which showed you best practices approaches when using Swing. The presentation talked about how to create effects in Swing and what the new Timing Framework is all about. All the talking about the cool stuff you can do with Swing makes me want to do a little Swing project…The corresponding book might be a good buy.
Next was the presentation titled “Java SE 6 Top 10 Features and Java SE7”. The presentation talked about all major new features in Java 6 such as the script engine support, support for webservices, GUI improvements (I like the built-in support for Splash screens) and the SwingWorker support.

One feature, that looked quite intriguing were the Troubleshooting Tools of Java 6.

The next talk was all about Dojo. The widgets are nice but for straight server calls I do prefer DWR instead of hand-coding some JSon structures. Unfortunately, the presentation did not mention DWR once. Nevertheless, it will be interesting to see what happens since DWR joined the Dojo Foundation.

The last presentation of the conference compared a Java EE application, a Seam application and a Spring application to each other using JPA and JSF. All three applications implemented the same feature set.

That was it – Afterward Sun provided free beer and wine and I spent a little bit more time networking before heading back home…writing this blog.

Thursday, January 10, 2008

Renewable Energy – Falling behind…

Over the holidays my wife and I spent two weeks in Germany. We stayed with my family in a small suburban town east of Berlin. Roughly once every year I get a chance to go back ‘home’. Usually not too many things change from year to year. But this year I got amazed of how mainstream solar energy is getting these days even for ordinary people.

Basically every new home construction is installing at least Solar thermal collectors. These collectors basically use the Sun to heat up water. This can be used to generate a good portion of your home’s warm water needs. You can furthermore use it for powering your floor heating system (This is really nice). But you also see quite a few homes (new and old) being equipped with photovoltaic panels which are used to convert solar energy to electricity. All this is in addition to all those countless wind mills you see everywhere while driving across the countryside.

Well, I live in Atlanta, GA and I cannot remember having ever seen solar panels here that are used for residential purposes (Please let me know if you know of some). I know that there are some promising developments going on in California (e.g. Google), Oregon and Washington. Furthermore we have some promising environmental groups here in Atlanta such as the Southface Energy Institute. However notwithstanding, I feel that the country as a whole is falling behind compared to many European countries when talking about renewable energy. We must do better, much better.

Especially, here in the southeastern United States solar energy should be a no-brainer. Take Atlanta - It is on the same latitudes as North Africa and we get plenty of sunshine here.