我加入Java庫的.jar文件,並嘗試連接到Solr的,代碼如下:solrJ錯誤HttpSolrServer和SolrServer
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
@vinod我是新手,可以更具體嗎? –
檢查答案。 – vinod