gpt4 book ai didi

java - 在java异常中使用Solrj

转载 作者:行者123 更新时间:2023-12-01 05:01:01 24 4
gpt4 key购买 nike

我想在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com