yanfangsheng123 发表于 2016-12-14 09:09:22

关于solr中ClassNotFoundException: solr.extraction.ExtractingRequestHandler

  前面解决了solr部署在tomcat中报错的问题,可是再解决使用solr索引pdf,word文档的时候,又报错了:
  java.lang.ClassNotFoundException: solr.extraction.ExtractingRequestHandler 。
  分析原因,应该是该类所在的jar包没有包含进去,后来按照wiki :http://wiki.apache.org/solr/ExtractingRequestHandler中的要求把所有的jar包都放到项目的lib目录下,仍然不行,看来是没法加载到这个jar包。
  于是,我直接使用solr自带的jetty服务器来测试,看看是否也有这个问题,结果是没有任何问题。于是查看配置文件:solrconfig.xml,发现其中有关于lib目录的定义:

<lib dir="../../contrib/extraction/lib" />
<!-- When a regex is specified in addition to a directory, only the
files in that directory which completely match the regex
(anchored on both ends) will be included.
-->
<lib dir="../../dist/" regex="apache-solr-cell-\d.*\.jar" />
<lib dir="../../dist/" regex="apache-solr-clustering-\d.*\.jar" />
<lib dir="../../dist/" regex="apache-solr-dataimporthandler-\d.*\.jar" />
<!-- If a dir option (with or without a regex) is used and nothing
is found that matches, it will be ignored
-->
<lib dir="../../contrib/clustering/lib/" />
  仔细分析这段xml代码,会发现在jetty中测试时,是可以找到那些对应的jar包,但是我是直接复制的conf和data目录到tomcat中solr目录下的,没做任何修改,于是就会出现找不到jar。想到这里,于是就把contrib和dist目录拷贝到tomcat中的solr目录下,然后修改其配置文件solrconfig.xml为:

<lib dir="contrib/extraction/lib" />
<!-- When a regex is specified in addition to a directory, only the
files in that directory which completely match the regex
(anchored on both ends) will be included.
-->
<lib dir="dist/" regex="apache-solr-cell-\d.*\.jar" />
<lib dir="dist/" regex="apache-solr-clustering-\d.*\.jar" />
<lib dir="dist/" regex="apache-solr-dataimporthandler-\d.*\.jar" />
<!-- If a dir option (with or without a regex) is used and nothing
is found that matches, it will be ignored
-->
<lib dir="contrib/clustering/lib/" />
  注意,这些目录的起始位置是solr.solr.home。
  在这样修改以后,再次运行测试程序,一切ok。
  备注:测试的代码来自于:http://wiki.apache.org/solr/ExtractingRequestHandler
  测试的文档为solr中docs目录下的tutorial.html文件
  最后在地址栏中输入:http://localhost:8080/solr/select?q=attr_content:tutorial 即可看到结果
  
页: [1]
查看完整版本: 关于solr中ClassNotFoundException: solr.extraction.ExtractingRequestHandler