Exception in thread “main” Java lang.NoClassDefFoundError:org / apache / commons / codec / DecoderException

I try to query Solr through solrj

This is my code

public class ReadFromSolr {

public static void main(String[] args) throws MalformedURLException,SolrServerException 
{
     String url = "http://localhost:8983/solr";
      try{
     SolrServer server = new CommonsHttpSolrServer(url);
     ModifiableSolrParams params = new ModifiableSolrParams();
       params.set("qt","/select");
        params.set("q","name");

            QueryResponse response = server.query(params);

            System.out.println("response = " + response);

      }

         catch (MalformedURLException ex) {
            ex.printStackTrace();
        } 
      catch (SolrServerException ex) {
            ex.printStackTrace();
        } 


}

}

It gives me an exception

PS. my peoject has the following cans:

** apache – commons-logging, * httpclient -4.2, httpcore 4.2. 1, slf4j – api 1.6. 2, apache – solr – solrj -1.4. 0 ***

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
        at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
        at org.apache.commons.httpclient.methods.getmethod.<init>(getmethod.java:89)
        at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:288)
        at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:243)
        at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
        at org.apache.solr.client.solrj.solrServer.query(SolrServer.java:118)
        at com.gismo.ReadFromSolr.main(ReadFromSolr.java:27)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
        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)

Solution

Commons codec. Is required on the classpath jar.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>