Trying to use JCR with Jackrabbit

What are JCR and Jackrabbit?

The Java Content Repository API (JCR) is a specification which defines how to access a content repository. Apache Jackrabbit is the best known implementation of it, but there are more. One of the advantages of using JCR is that functionality like versioning is provided. Jackrabbit supports storing the repository in a local directory, but it can be stored in a database as well.

Getting started

As Jackrabbit provides the implementation of the API, it would make sense to go to the Jackrabbit site in order to get documentation to get started. However, I’ve found that the getting started page really wasn’t helping much. Also, there is quite a large amount of artifacts available, so knowing which ones you need was troublesome for me. One of the dependencies was jackrabbit-webapp, so I tried deploying that. It worked and it basically has 2 functions: create repository and connect to repository. However, when I try to create a repository I get an error that the repository already exists, and when I try to connect to it, I get an error that the repository doesn’t exist. It also didn’t show any info on how to fix it, so that didn’t help.

Getting started try 2

The First Hops page at the jackrabbit site does help a lot. For example: this shows what dependencies to use and provides useful code samples.

Starting to use Jackrabbit

The latest version of Jackrabbit 2.3.x didn’t work at my project because of a version conflict with slf4j, but after adding the following to my pom.xml, it worked.

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
</dependencyManagement>

Getting it to work

Getting the code at First Hops working works like a charm. However: after creating a war file, and deploying it in Tomcat, it ceased working. Also, most documentation which I could find is about Tomcat 5 or lower, but at Itude Mobile we’re using Tomcat 6.

A site which did help me can be found at http://ctpjava.blogspot.com/2008/09/adding-jcr-support-to-your-existing-web.html.

Using Jackrabbit

I want to store data on a specific location and create the corresponding nodes if this location doesn’t exist yet. I needed about 50 lines of code in order to get this to work, which was a bit disappointing to me, but it worked.

Versioning is another story. The Versioning basics example at the Jackrabbit wiki uses deprecated code and doesn’t retrieve the content of an old node so it is pretty useless. However, I have found another article which also uses deprecated code, but which does access data from a node from an old version. However: this example didn’t work: I got a javax.jcr.PathNotFoundException.

Giving up

In the end, I gave up on JCR / Jackrabbit and started storing my contents in a good ol’ database. The main advantage for me is that I already have experience with that. Maybe JCL/Jackrabbit is still a nice framework for my needs, but for now I’m sticking with something I know it will work.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s