This post is a brief guide on how to get Apache Jackrabbit and to write an Eclipse plugin that works with it.
Jackrabbit is an open source implementation of the Java Content Repository defined in JSR 170. Current stable version is 1.6.0 and they have alpha builds of 2.0 version that should implement JSR 283, the next revision of the JCR.
Running Jackrabbit is easy: download jar with standalone server jackrabbit-standalone-1.6.0.jar and launch it:
dimzzy@hornet:~ $java -jar jackrabbit-standalone-1.6.0.jar Welcome to Apache Jackrabbit! ------------------------------- Using repository directory jackrabbit Writing log messages to jackrabbit/log Starting the server... Apache Jackrabbit is now running at http://localhost:8080/
After this Jackrabbit will create a JCR repository with default workspace and you may connect to it from a web browser at http://localhost:8080/.
The next step is to put in some data. You may do it right within the browser by following the Populate link and harvesting internet for data or by mounting WebDAV directory http://localhost:8080/repository/default/ and copying some files and folders there. Default administrator account is admin/admin.
Accessing Repository
Now launch Eclipse and create a new plugin project. Our client will be a simple repository browser that shows a tree of nodes so add a view part with a TreeViewer. To use JCR API we will also need a jar (jcr-1.0.jar) with all the classes and interfaces which you can download here: JSR 170 downloads.
In order to connect to the running Jackrabbit you will need three more jars:
- jackrabbit-api-1.6.0.jar
- jackrabbit-jcr-commons-1.6.0.jar
- jackrabbit-jcr-rmi-1.5.0.jar
The tricky part is that I was unable to download them directly so I had to download jackrabbit-webapp-1.6.0.war and extract those jars from there.
Here is code that creates the viewer:
public class RabbitViewPart extends ViewPart {
private TreeViewer viewer;
private Session session;
@Override
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent);
viewer.setContentProvider(new JCRContentProvider());
viewer.setLabelProvider(new JCRLabelProvider());
try {
Repository repository
= new URLRemoteRepository("http://localhost:8080/rmi");
session = repository.login(null, null);
viewer.setInput(session.getRootNode());
} catch (Exception e) {
Activator.error(e);
}
}
@Override
public void dispose() {
session.logout();
super.dispose();
}
@Override
public void setFocus() {
viewer.getControl().setFocus();
}
}
The code is pretty straightforward: when view part is created we connect to the Jackrabbit instance using URLRemoteRepository and open a session. First null means that we want the default workspace and the second null means that we login anonymously. Running browser looks like this:
You can download complete source code here.







