2

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry i am still a bit confused. How do i deploy solrj into the web server? i am currently using solr-solrj-4.10.3.jar. do i have to set up anything like environment path etc? i saw guides that tell me to do that and to set up maven..but since i am using the jar file i do not have to go through that right? I have no syntax error but on runtime it returns HttpSolrServer not found error.
What is your webserver? Tomcat? JBoss? Jetty? Any of your web servers have a "lib" directory. For example, C:\apache-tomcat-8.0.18\lib . You have to copy your JAR into that folder. The error you're running into is that your code can see the JAR when you're compiling (I'm guessing in an IDE like Eclipse), but when you're running it, it can't see your JAR any more. Maven can allow you to package the solrj JAR into your deployable artifact (WAR) so that you don't have to put it in the webserver's lib directory. Either way works.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.