【发布时间】:2017-04-13 07:05:26
【问题描述】:
我已经在java库中添加了.jar文件,并尝试连接到solr,代码如下:
import java.net.MalformedURLException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
public class SolrQuery {
public static void main(String[] args) throws MalformedURLException, SolrServerException {
SolrServer server = new HttpSolrServer("http://localhost:8080/solr");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "1");
QueryResponse response = server.query(params);
System.out.println("response = " + response);
}
}
但是当我尝试运行程序时,我得到了错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
SolrServer cannot be resolved to a type
HttpSolrServer cannot be resolved to a type
The type org.apache.solr.common.params.SolrParams cannot be resolved. It is indirectly referenced from required .class files
我该如何解决?
【问题讨论】:
-
添加集合名称 url 或设置集合名称。
-
@vinod 我是 solr 的新手,可以更具体一点吗?
-
检查答案。
-
这听起来像是一个 Eclipse 问题——您使用的是 Eclipse 吗?你是怎么编译的?您如何尝试运行该程序?你是如何将罐子添加到项目中的?你加了哪些罐子?
-
是 .jar 文件的原因吗?我已经导入:commons-io-2.5,httpclient-4.4.1,httpcore-4.4.1,httpmime-4.4.1,jcl-over-slf4j-1.7.7,noggit-0.6,slf4j-api-1.7.7, stax2-api-3.1.4,woodstox-core-asl-4.4.1,zookeeper-3.4.6,solr-solrj-6.5.0