Apache Solr: How I solved a problem with including DataImportHandler

07 Mar 2013
Posted by jcfiala

So, I'm setting up a solr server (version 4.1), using Tomcat6, for development. Not a problem, until I try including the DataImportHandler, where everything just breaks.

If you're not familiar with the DataImportHandler, you should have a look. It's a very nice looking piece of code that helps you import data into Solr easily, keeping track of changed data and all. I'm looking forward to using it for a project which doesn't use the usual apache solr Drupal modules.

Alright, so the problem had to do with including the jar files, which for me means including solr-dataimporthandler-4.1.0.jar. The obvious way from looking at the solrconfig.xml is <lib dir="../../../dist/" regex="solr-dataimporthandler-.*\.jar" />. Looking at my setup, I saw that the solrconfig.xml was two directories below the directory containing dist, so I shortened the dir path to ../../dist/, and it failed. And it kept failing.

I wasn't sure if the problem was if tomcat could find the file or if it could use the file, and I got a bit out into the weeds tracking things down, until I changed the dir to the absolute path for the directory, "/opt/solr/dist", and everything worked. The problem ended up being that the directory isn't relative to where the solrconfig.xml is, but to where the solr instance is sitting - which was one directory higher. So, what I ended up needing to do was:

<lib dir="../dist/" regex="solr-dataimporthandler-.*\.jar" /> -->

Which assumes that dist and the directory which is my solr core are at the same level, really. But if you're having trouble including your DataImportHandler, try shifting around that dir directive and see if that's your problem.

Tags: