iPhone location data

April 30th, 2011 by nils

Most of you have probably read about the fact that the iPhone stores location related information in a local file. The file is transferred to the computer every time the iPhone is connected and synced via iTunes. If you’re interested in visualizing the data, there is an application called iPhone tracker available at http://petewarden.github.com/iPhoneTracker. The authors of the software, Alasdair Allan and Pete Warden, didn’t only decide to open source their work, but also wrote up quite a bit of documentation about the data and how to access it. They promise that “none of your data ever leaves your machine” but go on to “recommend inspecting the source code if you’re a developer, or even just relying on the directions that allow you to inspect the data using standard database tools.”

So I thought hey, I’m a developer, so let’s see what I can do with those directions and a bit of java code… I documented the result in the little video below and also created a small google code project at http://code.google.com/p/java-location-data-converter. Right now it is just a JUnit test that generates a CSV file which you can then use to e.g. visualize the data with OpenHeatMap (http://www.openheatmap.com). If you have an iPhone and are curious to inspect your location data, check out the the directions to inspect the data.

And if you’re also a java developer, check out my code as a starting point.

Have fun!

iPhone location data visualized from Nils Preusker on Vimeo.

POST Attributes with Restlet 2

April 28th, 2011 by nils

Since I keep forgetting how to do this, here is a code snippet to POST parameters to some URL using Restlet 2:

Client restletClient = new Client(new Context(), Protocol.HTTP);
Reference resourceRef = new Reference("THE URL...");
resourceRef.addQueryParameter("key", "value");
Request request = new Request(Method.POST, resourceRef);

Response response = restletClient.handle(request);
String responseAsText = response.getEntityAsText();

Oh, and you’ll want to add the following dependencies to your maven pom.xml (if you’re using maven…):


Java Serializable and serialVersionUID

January 14th, 2010 by nils

Here’s a question:

Is a serialVerionUID required on abstract classes?

My first thought: No way! If the serialVersionUID is used by the serialization mechanism to check whether some serialized data is compatible with a serializable class, abstract classes (that will never be instantiated, and thus, never be serialized directly) don’t need one! The problem is that the entire inheritance tree is checked when a class is de-serialized — and that includes abstract base classes. A simple example illustrates the problem:

If we have an abstract base class …

import java.io.Serializable;

public abstract class Base
implements Serializable {}

… and a sub-class that declares a serialVersionUID …

public class Sub extends Base {
    private static final long serialVersionUID =

… and we create an instance of the sub-class and serialize it to a file …

Sub sub1 = new Sub();
try {
    FileOutputStream fout = new FileOutputStream("sub.dat");
    ObjectOutputStream oos = new ObjectOutputStream(fout);
} catch (Exception e) {

… and then we change the base class by e.g. adding an int field …

import java.io.Serializable;

public abstract class Base
implements Serializable {
    int a = 0;

… and try to de-serialize the sub-class …

Sub sub2 = null;
// Load the file and de-serialize the object
try {
    FileInputStream fin = new FileInputStream("sub.dat");
    ObjectInputStream ois = new ObjectInputStream(fin);
    sub2 = (Sub) ois.readObject();
} catch (Exception e) {

… we’ll get a “java.io.InvalidClassException”.

If we do the same thing, but define a serialVersionUID in the abstract base class, the exception would not occur. The reason for this is, that if a serialVersionUID is not explicitly declared, the JVM will calculate a default one, “based on various aspects of the class” [1]. This is a great mechanism, at first glance it even seems to be better than creating the id manually — if the class changes, these changes are automatically reflected in the generated id. But, this mechanism can differ based on the VM If you would run this example on one VM and then try to de-serialize the same “sub.dat” file with a different VM, without modifying the base class, it is possible that you would get an “InvalidClassException”, simply because the VM uses a different mechanism to calculate the default serialVersionUID. This is why it is recommended to manually declare the serialVersionUID.

However, this also means that, if we change a serializable class and thereby make it incompatible with previously serialized instances, we have to update the serialVersionUID!

Now if we think about software maintenance and data integrity, there should be a way to migrate existing serialized data to new versions of the serializable class. I’d be interested to know if there is an official recommendation for this, but didn’t investigate further yet.

It would also be interesting to see how OR-mapping frameworks fit into the picture. There is an interesting thread on using Serializable and what to do with the serialVersionUID in the hibernate JIRA: http://opensource.atlassian.com/projects/hibernate/browse/HBX-964

I’d be interested to know what others think about this, so please feel free to comment!

[1] http://java.sun.com/javase/6/docs/api/java/io/Serializable.html

Eclipse on Snow Leopard (10.6.2)

November 24th, 2009 by nils

When I downloaded and installed Eclipse (eclipse-SDK-3.5.1-macosx-carbon.tar.gz) yesterday, I started to get the following error message:


Eclipse error message: "Cannot complete the request. This installation has not been configured properly for software updates!"

To fix this, you need to go to “Preferences > General > Capabilities” and check “Classic Update”. Afterwards you should be able to select “Help > Software Updates > Find and Install…”.

I wasn’t able to find much on the internet, but this post on an Ubuntu forum finally brought the solution.

Maven Dependency Conflicts

September 24th, 2009 by nils

Have you ever seen an exception like this:

org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'XY' defined in class path resource
[applicationContext.xml]: Instantiation of bean failed; nested
exception is org.springframework.beans.
BeanInstantiationException: Could not instantiate bean class
[XY]: Constructor threw exception; nested exception is
java.lang.LinkageError: You are trying to run JAXB 2.0 runtime
(from jar:file:/.../WEB-INF/lib/jaxb-impl-2.1.8.jar!/com/sun/
xml/bind/v2/model/impl/ModelBuilder.class)but you have old
JAXB 1.0 runtime earlier in the classpath (at jar:file:
WhiteSpaceProcessor.class) Please remove the JAXB 1.0
runtime for 2.0 runtime to work correctly.

Well, I have, several times… and the task of having to figure out which library causes this dependency conflict seemed unresolvable pretty scary at first! Luckily, there is the m2eclipse plug-in with its excellent dependency graph. So if you are using Eclipse, whether you are actually using m2eclipse to manage your project or not, just the dependency graph makes it worth having a look at it. I still run my maven tasks on the command line, but have m2eclipse installed, just to be able to use the graph.

Dependency Graph

After identifying which library is causing the dependency conflict, all you have to do is to add an “exclude” node to that dependency in your pom.xml. In the above case, this snipped did the trick:

    <exclusions>         <exclusion>             <artifactId>jaxb-impl</artifactId>             <groupId>javax.xml</groupId>         </exclusion>         ...     </exclusions>

Java and Snow Leopard

September 22nd, 2009 by nils

I noticed that there isn’t a whole lot of useful information about Java and Snow Leopard (OS X 10.6) out there on the web. Maybe this is because there isn’t a whole lot to say about it. Snow Leopard comes with Java 6 (1.6.0_15 that is) only, which means that the links that still exist in the


directory all point to “CurrentJDK”, which points to “1.6”. The thing is that Snow Leopard ships with a 32 bit version and a 64 bit version of the VM (Virtual Machine), 64 bit being the default one. The Java Preferences app shows this nicely:

Java Preferences Application

And that is the big news about it, since a 32 bit version of java 6 didn’t previously exist for OS X.

Now I’ve previously had to tweak Eclipse to use the 1.5 VM (see “Java Versions on Mac OS X“), and now it just works. I’m assuming that this is because of the “mixed mode”:

$ java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)

…so the VM would automatically detect if an application should be executed in 64 or 32 bit mode and then start the correct VM. I still need to investigate how this actually works. Anyway, the good news is that java and eclipse seems to be working better with Snow Leopard. I’ll write more on this as I continue working with it, for now here is an interesting post on the topic:


Different Maven Versions on OS X

April 24th, 2009 by nils

I keep running into the problem that different projects I’m working on require different versions of maven. I have two versions installed, maven 2.0.6 in /usr/share/maven-2.0.6 and maven 2.0.9 in /usr/share/maven. To find out which version of maven you are running, open a terminal and type the following

$ mvn --version
Maven version: 2.0.9
Java version: 1.6.0_07
OS name: "mac os x" version: "10.5.6" arch: "x86_64" Family: "mac"

In this case, maven 2.0.9 is running, so we’ll see how to switch to maven 2.0.6. First we need to know where the maven executable, or in this case, the symbolic link to the executable is located:

$ which mvn

Next, we’ll use ls to check where the symbolic link is pointing:

$ ls -l /usr/bin/mvn
lrwxr-xr-x  1 root  wheel  24 Apr 24 14:26 /usr/bin/mvn -> /usr/share/maven/bin/mvn

Finally, if you have different maven versions installed, you can switch between them by overwriting the symbolic link:

$ sudo ln -fhsv /usr/share/maven-2.0.6/bin/mvn /usr/bin/mvn

After providing your password, the symbolic link should now be pointing to the maven 2.0.6 executable. To doublecheck, type

$ mvn --version

The output should be something like this

Maven version: 2.0.6

Java Versions on Mac OS X

March 3rd, 2009 by nils

Update: This post refers to OS X 10.5 “Leopard”, if you are using 10.6 “Snow Leopard”, you might want to consider reading my post “Java and Snow Leopard” instead.

I just started using my Mac as a development machine and thought I’d share some of the issues and solutions I came across. I’m using Java 6, Tomcat 6, Eclipse 3.3.2 (Europa), hibernate 3, Spring 2.0.3 and tapestry 1.4.5.

The first issue I came across was an

UnsupportedClassVersionError: Bad version number in .class file

error when I tried to start tomcat. (I’m using the sysdeo plug-in to control tomcat, even though I’m aware that WTP is much better… I have my reasons, but that’s beyond the scope of this post.)

Now the title of the console in Eclipse revealed the problem, the Sysdeo plug-in was using version 1.4 of the Java RE. The thing is, I didn’t notice this until I tried a whole bunch of other stuff… which cost me quite a bit of time, but also helped understand a few things better.

OS X keeps the different Java versions neatly separated in the


directory. By creating or overwriting the symbolic link “CurrentJDK”, you can change the default JDK version of your system. To do this, you have to change to the Versions directory and set a new symlink with ln:

$cd /System/Library/Frameworks/JavaVM.framework/Versions
$sudo ln -fhsv 1.6 CurrentJDK

After providing the administrator password, the default JDK will be set to version 1.6. Unfortunately, after doing this, I couldn’t start Eclipse anymore. The fix for this is to edit the following file:


and un-comment the following line:


This tells Eclipse to use a specific Java version, instead of the platforms default one. Now I was able to start Eclipse again and tomcat started without exceptions when I manually deployed my war files. My next step was to try Sysdeo to start Tomcat, which is where I realized that all I would have had to do was to set the correct JVM in Preferences > Tomcat > JVM Settings. Anyway, learned something on the way :)

Here are some links that helped me: