Skip to content

Category Archives: Java

Java specific articles

Enforcing Fluent API adherence using Interfaces in Java

07-Jul-11

This some considerable noise on the internet about Fluent APIs and using them. There was a question on stackoverflow.com about how to enforce calling all the required methods to guarantee you fully materialize an object when using a Builder Pattern with a Fluent API approach. The appropriate way to achieve this is through Interfaces that [...]

The final word on final

09-May-11

Where is final used? There are a lot of Java developers that don’t understand the keyword final. The keyword final is one of your greatest allies in writing bug free maintainable code. It makes reading code much more deterministic and step debugging a breeze. And it makes your code side effect free. Side effects are [...]

Releasing Maven Artifacts to Central Repository through Sonatype

22-Mar-11

I have released my first Maven artifacts to the Central Repository through Sonatype’s Open Source Nexus Server. You have to jump through some hoops to get everything just right to be able to release to the Sonatype Nexus repository, and I could not find all the information I needed in one place so I will [...]

How to combine GWT and Jasper Reports using Maven

11-Mar-11

Make your pom.xml dependency entry for Jasper Reports look like this If you don’t use the excludes directive you get the java.lang.NoSuchFieldError: reportUnusedDeclaredThrownExceptionIncludeDocCommentReference error. <dependency>     <groupId>net.sf.jasperreports</groupId>     <artifactId>jasperreports</artifactId>     <version>3.7.4</version>     <exclusions>        <exclusion>             <artifactId>jdtcore</artifactId>             <groupId>eclipse</groupId>           </exclusion>     </exclusions> </dependency>

JSAP Command Line Application Maven Archetype

28-Feb-11

I have created my first Maven 2 / 3 Archetype for generating command line applications that are powered by Java Simple Argument Parser ( JSAP ). Its source code lives on GitHub. I am working on getting it posted to Sonatype and synced to Central Repository.

A Generic Object Oriented replacement for large Switch / Case and If / Else statements in Java

22-Feb-11

I saw this post on StackOverflow and thought I would whip up a quick Object Oriented solution using Generics using the Chain of Responsibility Pattern. This was a quick exercise to see how it might look. There are many other ways that this could be implemented, like using Dependency Injection to supply the implementations of [...]

Reading data from a file on the classpath in Java

22-Feb-11

Sometimes you want to load data at runtime from inside a .jar file or .war file to populate at List or Map or something. Here is how to do that easily. Just make sure that your data file is in the same package along side the Class that is loading it, or refer to it [...]

Working Maven 3 Google App Engine Plugin with GWT support.

06-Feb-11

I spent a great deal of time getting this to work. I could not find a single source of information on what all the needed dependencies and repositories were, so there was a lot of trial and error involved. This first version is configured for GAE 1.4.0 and GWT 2.1.1, the latest versions at the [...]

How to install the Offical Oracle JDK on Centos 5.5 and add select it as the default JDK

02-Nov-10

Here’s the command to install an alternative installation of Java: I installed JDK 6u22 from the executable rpm.bin file from the Oracle site. Then I ran this command to add it to the alternatives program. alternatives –install /usr/bin/java java /usr/java/jdk1.6.0_22/bin/java 99 then you just run alternatives –config java There are 3 programs which provide ‘java’. [...]

Migrating Java Projects to Maven 2

13-Jul-10

Looks like Maven 2 is pretty much inline with the generic Ant based build system I have been using for the past 8 years. So I am going to take the plunge and start using Maven 2 so I don’t have to keep maintaining my system. Less time maintaining a build system means more time [...]