线程“main”java.lang中的异常。NoClassDefFoundError:org/apache/commons/codec/DecoderException

时间:2022-01-20 15:36:46

I try Querying Solr via Solrj

我尝试通过Solrj查询Solr

Here 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();
        } 


}

}

}

and it gives me an exception

这给了我一个例外

PS. I've got the following jars in my peoject:

我的弹出框里有如下的罐子:

**apache - commons-logging,
*httpclient -4.2 ,
httpcore 4.2.1, slf4j - api 1.6.2,
apache - solr - solrj -1.4.0
***

**apache -公共日志,*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)

1 个解决方案

#1


12  

You need commons-codec.jar on the classpath.

你需要commons-codec。jar的类路径中。

#1


12  

You need commons-codec.jar on the classpath.

你需要commons-codec。jar的类路径中。