[英]Solr Insertion Using java
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import java.io.IOException;
public class FeedIntoSolr{
public static void main(String[] args) throws IOException, SolrServerException {
HttpSolrServer server = new HttpSolrServer("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 the Hobbit part " + i);
server.add(doc);
if(i%100==0)
server.commit(); // periodically flush
}
server.commit();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
at FeedIntoSolr.main(FeedIntoSolr.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 1 more
You need to add http client implementation You can update your pom.xml with maven 您需要添加http客户端实现您可以使用maven更新pom.xml
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
Or download it at https://hc.apache.org/downloads.cgi and add it to the classpath in Eclipse with Project > Properties > Build Path 或从https://hc.apache.org/downloads.cgi下载它,并通过Project> Properties> Build Path将其添加到Eclipse中的类路径中
Thanks to all for responding..I got the answer of question asked by me. 感谢所有人的答复。.我得到了我所问问题的答案。
1)first of all you need to add the jar files which is already available in solr folder(you will see when you unzipped it) 1)首先,您需要添加solr文件夹中已经可用的jar文件(解压缩后会看到)
2)Jar Files in the folder solr-5.2.1->dist( add only solr-solrj-5.2.1.jar in classpath) and solr->dist->solrj-lib(add all jar in classpath) 2)文件夹solr-5.2.1-> dist(仅在类路径中添加solr-solrj-5.2.1.jar)和solr-> dist-> solrj-lib(在类路径中添加所有jar )中的Jar文件
3)you have to add two another file commons-logging-1.2.jar and slf4j-simple-1.7.12.jar 3)您必须添加两个其他文件commons-logging-1.2.jar和slf4j-simple-1.7.12.jar
This is working for me.. 这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.