Persisting Joda-Time Fields with openjpa

Lately i became curious about how to store joda-time objects into a database with openjpa. Well, its supprisingly easy if you only want to store/retrieve the objects:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

import org.apache.openjpa.persistence.Persistent;
import org.joda.time.DateTime;

public class EntityA {
private Integer id;

private DateTime startDate;

Thats it .. of course what happens is, that openjpa does serialize the DateTime object and stores them as a BLOB field in the database, which might not be always the preferred solution.

Another way would be to add @Externalizer and @Factory annotations to the DateTime object, and write a custom convertor that would convert DateTime to SQL Timestamp or similar.

Posted in Uncategorized | Leave a comment

Reducing Raspberri PI’s memory usage

I just got my Raspberry pi recently and found this really usefull link for tuning Raspbian to use less memory :

Posted in Uncategorized | Tagged , , | Leave a comment

Git with Jenkins

Recently I did try to use jenkins together with git on windows. During configuration i stumbled along some blogpost that advised to use git.cmd instead of git.exe (which does set some more enviromnent variables, for example %HOME% to use _nettrc of curl)

Unfortunately using git.cmd leads to many very strange errors in jenkins, like missing branches, or ambiguous checkouts. Testing with some random Java project from github gave the same results, but reverting back to git.exe (and setting %HOME% for the serveruser manually) did the trick .. everything works correctly as expected 🙂

Posted in Uncategorized | Leave a comment

Hudson/Jenkins integration in Eclipse

Now, that the hudson-eclipse plugin seems dead for quite a while (not anything since 2009) i was briefly thinking about writing my own update with the xml-api by Jenkins.
But then i discovered that the mylyn project did what i wanted and even more ! With mylyn 3.5 there is an Jenkins/Hudson connector that will allow you to see the status of each job, see the test results, check the Jenkins console in eclipse, even provide a clickable changelog !

Check out the new features of !

Posted in buildmanagement, java | Tagged | Leave a comment

Logback Console in Eclipse

Recently i did find there is a console plugin for logback in eclipse. Unfortunately its based on a very old version of logback (0.9.9), so i searched for the sources, bumped the logback/slf4j versions to 0.9.28 and 1.6.1 and fixed various things in the plugin. Now there’s a new version of this plugin available here, i’ll post the sources to github soon.

This version is compiled with jdk 1.6 and has eclipse 3.6 as target platform. If you’ll need something else, drop a comment ..

The documentation at is still valid, just unzip the file in your plugins folder and select the logback view. After you did configure logback to use the console in logback(-test).xml things should start to show up in eclipse.
The neat thing is, that you can click on each logentry in the console to see where that specific logentry was created. Like linked stacktraces but for logfile enties.

*Update* Version 1.1.2 fixes an overlooked bug while viewing a stacktrace: logback eclipse Plugin 1.1.2

Posted in java, logging | Tagged , , , | 2 Comments

Running SoapUI Integration Tests in Hudson

Recently i’ve been wondering how to automate webservice(SOAP) integration tests. My first idea was to use soamoa, but it seems a bit buggy at the moment and the last version seems quite a while ago.

But SoapUI does offer a native maven plugin, which can run SoapUI testcases directly. So I set up a small maven project, and add a soapUI testcase like this:


Now, when i run “mvn test” from the command line, everything looks fine and the tests get correctly executed. But after I import the project in Hudson, i can’t see the test results 🙁 This seems to be a bug in Hudson, the only workaround at this point seems to create a freeform project in hudson instead of a maven2 one, add a maven2 step (mvn test), then add “**/target/surefire-reports/*.xml” under “Publish junit test results”. Now Hudson correctly does display all test results on the project page.

The only point left is to run multiple SoapUI projects from one maven project, for this one needs to add multiple <execution> tags, maybe the future versions of the soapui-maven-plugin will support easier configuration.

Posted in java, Testing | Tagged , , , | Leave a comment

Running selenium-hub inside Tomcat

The usual process of starting selenium-hub seems to be an ant goal that does run an integrated jetty server. While this is easy to run it is not so easy to run in a server enviromnent. Also, as i have an existing tomcat already running and the hub does not do that much i was wondering if i can run the server inside tomcat.

The first look was dissapointing, everything is bundeled in jar files, no war file in sight. Fortunately selenium-hub is just a bunch of servlets with some logic behind, so it should be easy to add some maven scripts to create a war file.

Selenium-hub also depends on selenium-core, which is also included in the selenium-hub distribution. So i created a fork of selenium-grid on github and add some maven scripts. You can see the results here: . Right now only the core and the hub part are mavenized.

A complete war-file can be found here: selenium-core-hub-1.0.8-SNAPSHOT

Posted in Testing | Tagged , , | Leave a comment

Introduction to Scala – Part 1

What is scala ?

Scala is a relativ new compiled programming language that takes a lot of ideas from python, ruby and others. From the scala homepage:

Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application.

Why do we need another programming language ?

I mean, there are a wealth of different languages that created quite a buzz recently like ruby, python, c#. Why do you need scala ? For one, scala is a compliled language unlike ruby and python. The scala compliler generates java-bytecode that is compatible with the java jre.
This looks like a small feature but it is really one of the most interesting features of scala:

Seamles Integration in java

You can directly use java objects in scala and vice versa. Scala directly compiles to java .class files. You can deploy scala applications to your J2EE container. Which means if you are a java shop you can use your existing tools and servers to deploy scala applications. No need for a new application server, JBoss, websphere and others will work fine.

This is a very important point for larger companies. Changes in these companies can only happen graduately, so you can keep your existing knowledge and workers. The server administrators still only need to maintain the same application server they’ve been knowing for years. You even can continue to use your own libraries you’ve developed in java over the years. These points are very important if you want to make a successfull migration towards scala.

Why use Scala over Java ?

If scala is fully compatible with java, why use it ? Why learn a new language when the old one seems good enough ?

  • Scala corrects many of javas mistakes
    • Everything is an Object in scala
    • Type inference -> only need to declare the type on the right side of the assignment (i.e. var dummy= Map[String,Int]() )
    • True Mixins
    • Scala is both, a object oriented and a functional programming language
  • Fresh start
    • Clean Language, nothing feels like an addon (like generics for example)
    • much more compact, like no need for getters and setters
    • No semicolons

Hello World in scala

Enough of the theory. How does a typical scala program look like ?

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
Posted in scala | Tagged , , | Leave a comment

zlib.dll not found when installing the current ruby-win32

Missing libraries

zlib.dll not found

After downloading the latest win32-releases of ruby i was greeted with two error messages, SSLEAY32.dll not found and zlib.dll not found. The SSL library is kinda optional (gem, etc basicly work without it), but zlib not.

For this, the zlib library is needed, luckily there’s a native win32 port of it. So, download the latest win32 dll from,
extract the zlib1.dll, rename it to zlib.dll and place it into the ruby bin directory.

SSLEAY32.dll not found

For SSLEAY32.dll the safest way i’ve found seems to use the version from the win32 postgresql client, which can be found here.

Just copy SSLEAY32.dll and libeay32.dll from the postgresql/bin directory into the ruby bin (or actually any other directory which is in your path)

readline.dll not found

Now you think everything is working, and start irb for the first time. Dang. readline.dll is missing. Readline win32 binaries can be found at Download the latest win32 build and copy the readline5.dll from the bin directory to your ruby bin directory again. Don’t forget to rename it to readline.dll.
Now everything should be working smoothly.

Posted in ruby on rails | Tagged , , | Leave a comment

Java.util.logging vs. slf4j

A bit of History

At the time the now discontinued log4j was the most commonly used logging framework for java sun decided to implement JSR 47: java.util.logging. There were a lot of discussion, but it seems not been fruitful. java.util.logging was introduced in JDK 1.4 and hasn’t changed much despite its obvious shortcomings.

The Good, The Bad and the Ugly

One of jul best selling points is the integration to J2SE 1.4. Why need another logging framework when there is one bundled with the SDK ? Unfortunately it seems the guys responsible for jul did create a similar mess like java.util.Date.

Whats good in JUL ?

  • Integration
    Everything is included in the SDK
  • Easy to get started
    Logger logger = Logger.getLogger(“de.glauche.test”);“my info message”);

Whats not so good in JUL ?

    The first seems ok, but FINE, FINER, FINEST ?
  •, logger.severe etc. only accept Strings
    This is a really bad case of inconsistent API, to log an exception for example you need to use logger.log(Level.SEVERE,”Some String”, exception); Why are there no shortcuts like logger.severe(“Some String”,exception); ?
  • no parameterized logging, which can be a severe performance penality

What is Parameterized Logging ? (and why should i care for it ?)

Imagine you have lots of debug logging statements in your code:

   logger.debug("Number " + i + " has the Value:  " + entry[i]);

Here, every time the code is reached the String is build first, which can be quite time-consuming if there are many variables which need to be converted to string and concatinated. This can affect the performance of the program quite a bit, especially if it is in some inner loop.
One common solution is to wrap the debug statement with an if-clause:

if(logger.getLevel() >= Level.DEBUG) { 
   logger.debug("Number " + i + " has the Value:  " + entry[i]);

Needless to say this leads to quite messy code, is unreadable and inflexible. Fortunately there is a very underused Class in java called MessageFormat, where you can use placeholders for parameters.
So, when using something like MesageFormat, you can use: format(String pattern, Object[] arguments) for a logger. The logger could decide if the log entry needs to be constructed or not. In worst case the overhead is just a function call.

SLF4j does exactly this. It uses parameterized strings as logmessages as default. So, the above log entry in slf4j would look like this:

   logger.debug("Number {} has the Value: {}",i,entry[i]);

Unfortunately SLF4j does not use javas overloading mechanism, so you can only add two Objects, or you need to create an array of them:

   logger.debug("Value {} was inserted between {} and {}.", new Object[] {newVal, below, above});

and the Ugly ?

So, whats really ugly in JUL ?

The configuration

The default configuration resides in the JDK/lib directory (!), but can be overwritten by a command line parameter. This is very bad in the J2EE enviroment where one JDK instance can contain many independed applications.
The configuration file is rather nice and straitforward, it is easy to replace parts, or set up log levels.

but wait, there is an API to configure JUL !

There is a limited API to configure the log settings, yes. But it has some drawbacks. First, it is not so easy to replace certain parts. For example when you just want to get rid of the ugly two line default output and have all info in one clean line. With the config file it is easy, but with the API you need to implement your own Handler first.
Another big drawback is that if you configure the root logger (“”), it is still classloader dependent. If some parts of your (J2EE for example) application use different classloader mechanism, the default configuration will be used.

so how does SLF4j help ?

SLF4j is, as the name implies a simple facade for logging. It does not really log anything for itself. For the real logging you can use the build in simplelogger, JUL (if you just want some nicer API for example), logback and even Log4J. On the other hand you can also redirect log-entries from other system into SLF4j, for example Java commons Logging (JCL).
This is especailly nice, as many different libraries still use JCL or log4j.
SLF4j configures the output by the logging implementation in the classpath. Switching the real logging mechanism is as easy as replacing a jar file in your classpath.
SLF4j is fast, one does not need to write if () wrappers around the debug statments, and it has nice parameterized logging.
On the bad side, you usually need at least two additional jars as dependencies in your project, the facade and the actual logger.

There’s also a short introduction how to automaticly construct logging fields in classes with the help of guice.

Posted in java | Tagged , , , | Leave a comment