((( Draft )))

Getting Started with JCR (Content Repository for Java, JSR-170) Page: 1

Page 1 |Page 2 | Page 3 | Page 4 | Page 5

This walk-through will make use of a collection of technologies to build a web based menu editor. The content for the menu data will be handled using the Content Repository for Java (JCR) API, the actual editor will be composed using DHTML and AJAX. Rather than write everything from scratch, existing open source tools and frameworks will be used. The JCR implementation used will be Apache Jackrabbit. The DHTML and AJAX framework used will be the Dojo Toolkit and DWR. The Spring Framework will be used to manage dependencies and configuration.


In order to get the most benefit from this article, a few pre-requisites will need to be met. You should know java and basic J2EE development (Servlets and JSPs). It will also be helpful if you have a general understanding of what the JCR (JSR-170) is. ((Find link to the class diagram)) If you have covered the First Hops at least through second hop, the going will be a little easier. This walk-through is kind of long so there will not be too many explanations. However, I will add detail blocks later on as time permits.

The tools for this walk-through are Java 5, Eclipse Callisto with the Web Tools Platform (WTP) installed. There are quite a few libraries needed, these can be found in the references section. They will be pointed out as we go along.

Setting up the Repository

Create a java project "jackrabbitTest". Add src, test_src, and lib directory. Copy all of the jars (from the Jackrabbit example or see Resources below) into the lib directory. In the build properties, set the src and test_src directories as source directories. Add all of the jars as libraries. Add the library JUNIT to the project. Finally, create a log4j.properties file in the src directory. Add the following 3 lines to it.


Optionally, just copy this log4j.properties file into the src directory instead. The eclipse environment should now look something like the following:

test case environment setup

Next, create a directory for the repository to live in. Copy this repository.xml file into that directory. Create a directory (call it repository) within this directory to actually hold the repository. Now, we are going to create a JUnit test to verify all of the parts work. CheckRepository.java If you have run the First Hops examples, on the Apache Jackrabbit site, you will notice, this is basically Hop 2. The difference is the System.out.println() calls have been replaced with asserts. Change the variables "repositoryConfig" and "repositoryHome" to the file and directory created before.

The first time the test is run, it will take a little while. It is initializing the Derby database, and creating the repository files. It will go faster on subsequent runs (you can also delete the subdirectories to clean the repository). If the test was successful, then along with the "green bar", there will also be some new directories in the repository home: repository, version, and workspaces.

Feel free to send comments to: feedback@willcode4beer.com
Page 1 |Page 2 | Page 3 | Page 4 | Page 5


About willCode4Beer