【发布时间】:2012-11-14 13:34:37
【问题描述】:
我想在 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
为什么我的代码不起作用?我必须做什么?
【问题讨论】:
-
看起来你的类路径中缺少
commons-httpclient.jar。 -
我添加了这个 jar,但我又得到了同样的异常:(
-
您使用的是哪个版本的 Solr?