This tutorial explains how to set up a Jackrabbit repository with Postgresql on Glassfish v3 and V2. I am using Ubuntu 8.10
I am going to use the
jackrabbit-webapp-1.5.0.war web application shipped with
Jackrabbit 1.5.0 to create a repository inside Glassfish.
In the next tutorial, a simple web application will then be created using Netbeans 6.5 to show how to programatically access the repository (insert and search) via Jndi from a servlet.
Repository set up in Glassfish
First of all, you need to copy the following libraries in the directory for Glassfish V3 Prelude:
$GLASSFISH/glassfish/domains/$DOMAINNAME/lib/ext/
and for Glassfish V2 in:
$GLASSFISH/domains/$DOMAINNAME/lib/ext/
where $GLASSFISH is your glassfish installation directory (i.e. glassfish-v3-prelude) and $DOMAINNAME is your domain (domain1 is the default).
The libraries are:
I suggest you compile the
Jackrabbit source using maven to get the needed jackrabbit libraries. The PDFBox and Poi libraries are for document text parsing and we will use them later.
Restart your domain and deploy the
jackrabbit-webapp-1.5.0.war you can use the Glassfish admin web tool (usally at
http://localhost:4848/) to deploy, I will assume you have deployed with a Context Root set to
/jackrabbit with
port 8080We can now test our installation by navigating to
http://localhost:8080/jackrabbit/ in your web browser and you should see the page below:

Notice, the web application uses a configuration file
bootstrap.properties located in:
$GLASSFISH/glassfish/domains/$DOMAINNAME/config/jackrabbit
You have to modify this file in case you want to change the repository or any setting. If you want to re-deploy starting with a fresh configuration you can delete the folder.
If you choose the default
jackrabbit repository it will be created in the same config directories we have just discussed for V3 Prelude:
$GLASSFISH/glassfish/domains/$DOMAINNAME/config/jackrabbit/repository
for V2:
$GLASSFISH/domains/$DOMAINNAME/config/jackrabbit/repository
Alternatevely, you can select any directory your user has read/write permssion, from now onwards I will assume the repository has been created in
$HOME/testrepository
PostgreSQL Configuration
It is now time to configure the repository (which by default use the built-in
Derby database) to use instead PostgreSQL.
First of all, create a database named
testrepository I will create one using PgAdmin with user
postgres and template
postgres.

Then add the jdbc postgresql driver
postgresql-8.3-604.jdbc4.jar again in the directory (V3 Prelude):
$GLASSFISH/glassfish/domains/$DOMAINNAME/lib/ext/
while for V2 in:
$GLASSFISH/domains/$DOMAINNAME/lib/ext/
PersistenceManager you can use, I prefer the Bundle Database PM.
In order to switch from Derby to PostgresSQL, edit the configuration file
$HOME/testrepository/repository.xml
look for the two entries under
Workspace and
Versioning:
<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.DerbyPersistenceManager">
<param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
<param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>
and substitute them with:
<PersistenceManager class="org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager">
<param name="driver" value="org.postgresql.Driver"/>
<param name="url" value="jdbc:postgresql://localhost:5432/testrepository"/>
<param name="schema" value="postgresql"/>
<param name="user" value="postgres"/>
<param name="password" value=""/>
<param name="schemaObjectPrefix" value="public"/>
<param name="externalBLOBs" value="false"/>
</PersistenceManager>
Few things to be aware of, the
schema entry is not really a DB schema but more the "type of DB", on the other hand the
schemaObjectPrefix is truly the schema, in this example I am assuming we will use the default
public schema. Of course, in the
password enter your
postgres user password.
Restart the Glassfish application server and if you use PgAdmin you should see the following tables being created: