java - 在java异常中使用Solrj

标签 java apache solr

我想在netbeans中使用Solrj,我编写了这段代码:

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;

public class SolrjPopulator {
  public static void main(String[] args) throws IOException, SolrServerException {
    CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://localhost:8983/solr");
    for(int i=0;i<1000;++i) {
      SolrInputDocument doc = new SolrInputDocument();
      doc.addField("cat", "book");
      doc.addField("id", "book-" + i);
      doc.addField("name", "The Legend of Po part " + i);
      server.add(doc);
      if(i%100==0) server.commit();  // periodically flush
    }
    server.commit(); 
  }
}

当我运行示例时,我收到此异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpConnectionManager

为什么我的代码不起作用?我必须做什么?

最佳答案

将缺少的库添加到用于执行应用程序的类路径中。 jar-finder has some libraries that contain this class ,它可能是 commons-httpclient。

关于java - 在java异常中使用Solrj,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379825/

相关文章:

java - 超时后终止长时间运行的查询

PHP 传递参数以执行奇怪的行为

java - 需要第三方框架的 Multi-Tenancy 功能

full-text-search - Solr查询唯一整数字段

java - 无限循环应用——for(;;)

java - 如何将模拟注入(inject)到需要构造函数参数的 bean 中

java - Solr-并发提交时OverlappingFileLockException

mysql - 如何从 MySQL 查询在 Apache-Solr 中形成自连接查询?

java - Spring MVC htmlspecialchars() 替代方案

java - 找到相应的 junit 类的 Eclipse 函数/插件?