简体   繁体   中英

Use Solr to index my database

I don't know why my code java is not compiled.

I need to index my database with solr.

I launch my server with line commande .

>cd C:\Solr\solr-4.10.0\solr-4.10.0\example\solr
>java -jar start.jar

After that i create a new project that contain my class to index database with solr.

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;



//import org.apache.lucene.index.IndexWriter;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;//   CommonsHttpSolrServer;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest.ACTION;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.impl.HttpSolrServer;


public class IndexFiles {

public static void main(String[] args) {


      HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/");
      // i use SolrServer but it generate same error like this from httpSolrServer
      //SolrServer solr = new HttpSolrServer("http://localhost:8983/solr");  
    /*
      // TODO Auto-generated method stub
    String urlString = "http://localhost:8989/solr";
    if (args != null & args.length > 1) {
        urlString = args[1]; 
    }

    SolrServer solr = new HttpSolrServer("http://localhost:8983/solr"); //CommonsHttpSolrServer(urlString);
    try {
        indexDocs(solr, new File(args[0]));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    */
  }
}

I get this error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException
at IndexFiles.main(IndexFiles.java:23)
Caused by: java.lang.ClassNotFoundException: org.apache.http.NoHttpResponseException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more

How to resolve this problem?

Sounds like you haven't added the httpclient jar (from dist/solrj-lib) to your classpath.

See the Solrj wiki page topic about: Setting the Classpath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM