Why can't I instantiate DataImportHandler in Solr on JBoss?

我与影子孤独终老i 提交于 2019-11-28 13:53:11

This is a class loader issue and according to this post on the Lucene Developer Mailing List you need to do the following:

make sure that the dataimport jars are NOT in the classpath and not loaded by other classloaders but from the path specified in solrconfig.xml. This will ensure that the dataimport classes are loaded by the same classloader.

Please see the thread for more details.

Paige Cook's answer is correct, but I'd like to add some details. I think you put the dataimporthandler jar into the common lib directory of your application server, while all solr jars are inside the WEB-INF/lib of solr.war. This means you're loading the dataimporthandler jar from a different classloader. You can solve it by putting your solr libraries in a different lib (external) directory. Then in your solr.xml you should refer to that lib folder through the sharedLib attribute. Something like this:

<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false" sharedLib="lib">
    <cores adminPath="/admin/cores">
        <core name="core1" instanceDir="core1" />
    </cores>
</solr>

This way the Solr web application will load jars from that external location through its specific classloader.

As said by Paige Cook this is a class loader issue, you should add dataimport jars into a path used by Solr class loader. In order to define such lib path there are many options. Old versions of Solr (4.x and older) accepts an attribute sharedLib in the tag :

<solr persistent="false" sharedLib="lib"></solr>
  • sharedLib - Path to a directory containing .jar files that are added to the classpath of every core. The path is relative to solr.home (where solr.xml sits).

Newer versions of Solr (5.x and newer) use sharedLib as a child node of solr element.

<?xml version='1.0' encoding='UTF-8'?>
<solr>
  <str name='sharedLib'>lib</str>
</solr>

Even in this case the lib path is relative to solr.home (where solr.xml sits).

Another alternative is define a lib directive directly into the solrconfig.xml,

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!