user3732861
user3732861

Reputation: 41

java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/HttpSolrServer

I am trying to perform query from my servlet to solr using solrj, however i am facing problem, apparently HttpSolrServer class is not found and i dont know why. Below is my servlet code

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub

      HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
        SolrQuery query = new SolrQuery();
        QueryResponse QueryResponse;
        try {
        QueryResponse = server.query(query);
         SolrDocumentList results = QueryResponse.getResults();
         System.out.println("hello2");
          for (int i = 0; i < results.size(); ++i) {
            System.out.println(results.get(i));

          }
    } catch (SolrServerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Thanks in advance

Upvotes: 2

Views: 5883

Answers (2)

Andrea
Andrea

Reputation: 2764

Your Servlet is in a web application which is deployed under a given servlet engine / application server.

Now, your web application has a WEB-INF/lib folder that contains all required dependencies (i.e. jars). You should get solrj with all its dependencies from a Solr distribution and put all of them in that WEB-INF/lib folder

Upvotes: 0

Josh Edwards
Josh Edwards

Reputation: 908

You need to make sure that you deploy solrj in your web server's lib folder (or include it in the WEB-INF lib folder of your war). The error you're getting is because when it's executing the code, it can't find solrj.

Upvotes: 1

Related Questions