Tuesday, August 14, 2012

JCR standalone with MySQL


In this post you'll see the steps required to use jackrabbit repository in mode:

 • manual
 • persistent (mysql)


I am going to use an update version of the code used in the previous two posts that can be found at https://github.com/mgardellini/jcr-poc (branch: manual_persistent). The database used is mysql but the same logic applies to any other like Derby or MSSQL.

1) create a database called jackrabbit in your local mysql installation
2) download jackrabbit 2.5.1 standalone from:


3) copy the downloaded jar in your <anywhere>/jackrabbit_home, let's call this dir JACKRABBIT_HOME

   java -jar jackrabbit-standalone-2.5.1.jar

5) wait for it to fully start then stop the server (ctrl+d)
6) copy repository/repository.xml to JACKRABBIT_HOME/jackrabbit
7) create the directory JACKRABBIT_HOME/lib
8) download/get from your local m2repo copy mysql-connector-java-5.1.21.jar in JACKRABBIT_HOME/lib
9) restart jackrabbit as:

   java -cp "jackrabbit-standalone-2.5.1.jar:lib/mysql-connector-java-5.1.21.jar" org.apache.jackrabbit.standalone.Main

10) access http://localhost:8080/ you should see the initial page and with error messages or forms of any kind
11) add this dependency to your pom:

   <dependency>

    <groupId>org.apache.jackrabbit</groupId>
    <artifactId>jackrabbit-jcr-rmi</artifactId>
    <version>2.5.1</version>
   </dependency>

10) change your code in order to use JcrUtils for logging in the repo (see this link for details):

   JcrUtils.getRepository("http://localhost:8080/rmi");

As you can see it is pretty straight forward. You can now either play with the tests in order to add and search nodes or you can add more beans to your implementation, save them and see how jackrabbit reacts.

You probably want to change the design of the DataHandler in order to avoid passing session, namespace, workspace and nodes. Again the project is a mere PoC for understanding how to setup and use Jackrabbit.

No comments:

Post a Comment