Skip to content

Running jackrabbit in tomcat with mysql

David Buchmann edited this page Jan 3, 2017 · 29 revisions

NOTE: See https://github.com/jackalope/jackalope-jackrabbit/issues/7 for the discussion on having a .rpm package and maybe .deb for jackrabbit with tomcat.

NOTE: On a developer system, the easiest is just running the built-in server with java -jar jackrabbit-*.jar

Prerequisites

This documentation assumes you have an environment with the following infrastructure:

  1. You have tomcat installed (e.g. apt-get install tomcat6)
  2. You know where the tomcat webapps directory is (e.g. /var/lib/tomcat6/webapps on Debian/Ubuntu).
  3. You have a mysql database setup and have the credentials for a database user that can create tables in the database.

Troubleshooting

If something goes wrong, your first point to look at is the tomcat logfile. On debian systems, it is at /var/logs/tomcat6/catalina.out

Add java libraries

Install the following two .jar files into tomcat's lib directory (/usr/share/tomcat6/lib on Ubuntu).

Now install the jackrabbit war (web application archive) file into the webapps folder:

Find the right version of the jackrabbit-webapp-X.war file from https://jackrabbit.apache.org/downloads.html e.g. http://www.apache.org/dyn/closer.cgi/jackrabbit/2.6.1/jackrabbit-webapp-2.6.1.war. Anything above 2.4 should be fine. The description below is tested with 2.6.5.

Then place that file into the webapp directory (e.g. /var/lib/tomcat6/webapps) and rename it to jackrabbit.war as that filename will be part of the url of the web application.

Make sure both .jar files and the .war file are readable by the tomcat user (e.g. tomcat6 resp tomcat7 on debian).

Setup

Start or restart tomcat (sudo service tomcat6 restart on Ubuntu). Once tomcat is running it will unpack the war file and put its content to the jackrabbit directory below webapps.

Shut down tomcat again. Copy the contents of bootstrap.properties into /opt/jackrabbit/bootstrap.properties (you need to create that directory first) and edit webapps/jackrabbit-/WEB-INF/web.xml to point bootstrap-config to that file. When not doing this, repository setup will not work.

Start tomcat again, and surf to localhost:8080/jackrabbit and say to create a new repository. Jackrabbit will create the repository in /opt/jackrabbit and then complain that it already exists.

Now stop tomcat again. We need to adjust three files to make tomcat use mysql for storage.

repository.xml

To get jackrabbit running with mysql you need to customize the standard repository.xml. You need to set up a PersistenceManager to use mysql:

Look for all elements with PersistenceManager:

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
    <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
    <param name="schemaObjectPrefix" value="${wsp.name}_"/>
</PersistenceManager>

and replace the definition with

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
    <param name="url" value="jdbc:mysql://127.0.0.1:3306/jackrabbit"/> <!-- use your database setup -->
    <param name="user" value="jackrabbit" />                           <!-- use your database user -->
    <param name="password" value="jackrabbit" />                       <!-- use your database user's password -->
    <param name="schema" value="mysql"/>
    <param name="schemaObjectPrefix" value="pm_ws_${wsp.name}_"/>
</PersistenceManager>

and

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.DerbyPersistenceManager">
    <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
    <param name="schemaObjectPrefix" value="version_"/>
</PersistenceManager>

with

<PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.MySqlPersistenceManager">
    <param name="url" value="jdbc:mysql://127.0.0.1:3306/jackrabbit"/> <!-- use your database setup -->
    <param name="user" value="jackrabbit" />                           <!-- use your database user -->
    <param name="password" value="jackrabbit" />                       <!-- use your database user's password -->
    <param name="schema" value="mysql"/>
    <param name="schemaObjectPrefix" value="pm_vs_"/>
</PersistenceManager>

You can find an already modified file here: https://github.com/jackalope/jackalope/wiki/files/repository.xml

boostrap.properties

In order to tell the web application where the repository is located we need to tell it in the file 'bootstrap.properties'.

The most important line is

# point this to your custom repository.xml
repository.config=/opt/jackrabbit/repository.xml

Here is a complete version of the file https://github.com/jackalope/jackalope/wiki/files/bootstrap.properties

web.xml

The last thing we need to do is tell the web application where bootstrap.properties is. This is done in the webapps/jackrabbit/WEB-INF/web.xml file:

Look for all occurences of bootstrap-config in the web.xml and point it to your bootstrap.properties:

<init-param>
    <param-name>bootstrap-config</param-name>
    <param-value>/opt/jackrabbit/bootstrap.properties</param-value>  <!-- replace with your location -->
    <description>
        Property file that hold the same initialization properties than
        the init-params below. If a parameter is specified in both
        places the one in the bootstrap-config wins.
    </description>
</init-param>

Find a usable file here: https://github.com/jackalope/jackalope/wiki/files/web.xml

Putting it all together

  1. File permissions: Make sure the user Tomcat is running under (e.g. tomcat6) can read all the archives and the configuration files.
  2. Start or restart tomcat (sudo service tomcat6 restart on Ubuntu). Once tomcat is running it will unpack the war file and put its content to the jackrabbit directory below webapps.
  3. Stop tomcat (sudo service tomcat6 stop on Ubuntu) and put your web.xml file in webapps/jackrabbit/WEB-INF replacing the existing (or edit the existing file as described above).
  4. Place repository.xml and bootstrap.properties in the jackrabbit directory you created, e.g. /opt/jackrabbit
  5. Start tomcat. Jackrabbit can now be reached at http://localhost:8080/jackrabbit/server (or whatever port your tomcat is running on).

##Index Data Ignoring Accent Symbols ######This is really usefull in Searchs. For example if you are looking for a Title like "WóW" you could find it looking for "WoW", this, simply replace accented symbol for it's not accent one. Doesn't modify any of your stored data.

  1. We need to tell tomcat to use a new Analyzer for indexing. So we create in a new project or whatever a new java file with this content.
java
package org;
import java.io.Reader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.ISOLatin1AccentFilter;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardFilter;
import org.apache.lucene.analysis.standard.StandardTokenizer;
import org.apache.lucene.util.*;
@SuppressWarnings("deprecation")
public class MyAnalyzer extends Analyzer
{
   @Override
   public TokenStream tokenStream(String arg0, Reader arg1)
   {
      StandardTokenizer tokenStream = new StandardTokenizer(Version.LUCENE_30,arg1); 
      TokenStream result = new StandardFilter(tokenStream);
      result = new LowerCaseFilter(result);
      result = new ISOLatin1AccentFilter(result);
      return result;
   }
}

  1. After compiling this file we need to copy the class file to jackrabbit WEB-INF classes directory, in the propper folder, in this example we copy it to /whereveryourtoumcatisinstalled/tomcat6/webapps/jackrabbit/WEB-INF/classes/org/MyAnalyzer.class

  2. Jackrrabit needs to know that we will use our Analyzer as default, so, we will modify /whereveryourtoumcatisinstalled/tomcat6/jackrabbit/workspaces/default/workspace.xml

We are only adding this <param name="analyzer" value="org.MyAnalyzer"/>

So, it will look like this

         <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
            <param name="path" value="${wsp.home}/index"/>
            <param name="supportHighlighting" value="true"/>
           <param name="analyzer" value="org.MyAnalyzer"/> <!--The added Code -->
        </SearchIndex>
  1. We are almost DONE, for last we need to erased existing index data and restart tomcat service for force an index reload.
rm whereveryourtoumcatisinstalled/tomcat6/jackrabbit/repository/index/ -rf
rm whereveryourtoumcatisinstalled/tomcat6/jackrabbit/workspaces/default/index/ -rf
service tomcat6 restart 

If you have other workspaces than the default workspace, also delete those other indexes.

Backup / Restore

If you need to restore the repository from a backup, you again need to delete the repository/index and workspace/default/index folders.