Jackrabbit on Tomcat6 with JNDI and PostgreSQL

Installation

Install tomcat and postgresql on your system and verify they are working correctly. On Debian/Ubuntu development systems you can install both with "apt-get". Be aware that many production sites prefer to install all server software manually.

(Sidenote: it is a considered good practice to use a separate partition for each service's data on a production server, e.g., for /var/lib/postgresql/8.3 and /var/lib/tomcat6. This makes it easier to perform specialized backups, migrate the data from one server to another, etc. There's little cost to this if you use Linux Logical Virtual Modules (lvm), and it's not really necessary on a development server.)

Create a ${catalina.home}/common directory and copy jcr-1.0.jar to it. Edit ${catalina.home}/conf/catalina.properties and add ${catalina.home}/common,${catalina.home}/common/*.jar to the common.loader entry. This allows us to add libraries to the server without mixing them with the standard tomcat libraries - something that's extremely helpful when things stop working and you aren't sure which library is the culprit!

Finally, edit /etc/default/tomcat6 to add -Djava.rmi.server.hostname=hostname to CATALINA_OPTS, where you have changed 'hostname' to a public network interface. If you don't do this the RMI library will probably pick something weird like 127.0.1.1 (NOT 127.0.0.1) and you'll spend hours knocking head-shaped holes in the wall. You will need to use a public network interface to allow others to connect to the RMI server.

Basic Configuration

* Create an external directory for the jackrabbit files. By default it puts them somewhere in the tomcat tree (under bin?), but it's a good practice to put that someplace external from tomcat since you may want to access the repository later via a mechanism other than the tomcat webapp. I put it under /srv/jackrabbit.

* Copy the bootstrap.properties and repository.xml files from /WEB-INF/templates to /srv/jackrabbit.

* Edit /WEB-INF/web.xml and change the value of all bootstrap-config parameters to /srv/jackrabbit/bootstrap.properties.

* Edit /srv/jackrabbit/repository.xml so all FileSystem stanzas use org.apache.jackrabbit.core.fs.db.DbFileSystem and all PersistenceManager stanzas use org.apache.jackrabbit.core.persistence.bundle.PostgreSQLPersistenceManager. Set schema to postgresql in each stanza's configuration.

* The DataStore stanza should use org.apache.jackrabbit.core.data.db.DbDataStore with a databaseType (not schema) of postgresql.

* Set all schemaObjectPrefix as described in other wiki entries. (I use FS_, FS_WSP_${wsp.name}, PM_WSP_${wsp.name}, etc.)

* In all of these stanzas set the driver to org.postgresql.Driver, the url to jdbc:postgresql://host:5432/dbname, and the user and password as appropriate.

Restart tomcat. The database should now contain about 20 tables, and more importantly we know that the basic infrastructure is in place and we just need to refine it to use JNDI.

JNDI Configuration

* If you unpacked the jackrabbit .war file as ROOT, edit ${catalina.home}/conf/Catalina/localhost/ROOT.xml. If not, edit conf/Catalina/localhost/jackrabbit-1.5.4.xml or whatever you named the webapp. This file may not yet exist. You want root to own this file, not the tomcat user, so prevent it from being overridden when redeploying the jackrabbit webapp.