Tuesday, July 20, 2010

Setting up shared Jackrabbit content repository

There are several deployment models which are described in detail by Jackrabbit. For our purpose the "Model 2: Shared J2EE Resource" seems to be the best applicable. This way to deploy a repository is to make it visible as a resource to all the web applications that are running inside a servlet container by registering the repository as a resource adapter to the application server. The repository is started and stopped with the application server. I'm going to describe all necessary steps for the GlassFish application server:

Open up "Resources/JNDI/Custom Resources" in the GlassFish administration console
  • Put in a JNDI name "jcr/repository"
  • Put in a resource type "javax.jcr.Repository"
  • Put in the factory class "org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
  • Create the property configFilePath, pointing to a configuration XML file with an absolute path on the server, e.g. "c:/repository/repository.xml"
  • Create the property repHomeDir pointing to the absolute filesystem path for the repository, e.g. "c:/repository"
Copy Jackrabbit dependencies to GLASSFISH_HOME/glassfish/domains/domain1/lib/ext. These are in case of Jackrabbit 1.6.2:
 commons-collections-3.2.1.jar
 commons-io-1.4.jar
 commons-lang-2.4.jar
 concurrent-1.3.4.jar
 derby-10.2.1.6.jar
 jackrabbit-api-1.6.2.jar
 jackrabbit-core-1.6.2.jar
 jackrabbit-jcr-commons-1.6.2.jar
 jackrabbit-spi-1.6.2.jar
 jackrabbit-spi-commons-1.6.2.jar
 jackrabbit-text-extractors-1.6.2.jar
 jcr-1.0.jar
 log4j-1.2.15.jar
 lucene-core-2.4.1.jar
 mysql-connector-java-5.1.12-bin.jar (if datastore is MySQL)
 pdfbox-0.7.3.jar
 poi-3.2-FINAL.jar
 poi-scratchpad-3.2-FINAL.jar
To configure resource factory in Tomcat, add a <Resource> element to the <Context> in the file context.xml (global) or in the server.xml (for specific web app)
<Context ...>
  ...
  <Resource name="jcr/repository" auth="Container"
            type="javax.jcr.Repository"
            factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory"
            configFilePath="c:/repository/repository.xml"
            repHomeDir="c:/repository"/>
  ...
</Context>
Jackrabbit dependencies have to be copied  to TOMCAT_HOME/lib. Now you can set up JNDI reference to jcr/repository and use JCR to manage content in the application server. The configured resource needs to be declared in the web.xml file:
<web-app>
    ...
    <resource-ref>  
    <description>JCR Repository</description>  
    <res-ref-name>jcr/repository</res-ref-name>  
    <res-type>javax.jcr.Repository</res-type>  
    <res-auth>Container</res-auth>  
    </resource-ref>
</web-app>
After all steps the repository will be created automatically by the registered above factory class.

3 comments:

  1. HI Oleg,
    I have implemented JackRabbit DMS.
    My only probelm is that when i deploy it linux, it fails every time. But when i manually delete repo home directory, it works. Note that I haven't mentioned jackrabbit dependency in web.xml. Could this be the problem?

    ReplyDelete
    Replies
    1. Sorry, I don't know. I don't develop DMS anymore :-)

      Delete

Note: Only a member of this blog may post a comment.