這是我使用的查詢Solr的指數的Servlet拋出異常
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
//Solr Imports
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.request.AbstractUpdateRequest;
/*
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
*/
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
PrintWriter out = response.getWriter();
String inputStr=request.getParameter("input");
out.println("<html><h1>" + inputStr + "</h1></body></html>");
//try {
SolrServer server = new CommonsHttpSolrServer("http://localhost:8080/solr/");
SolrQuery solrQuery = new SolrQuery();
//solrQuery.setQuery("fileName:"+input);
solrQuery.setQuery("Latitude:"+32.55668);
QueryResponse rsp = server.query(solrQuery);
//SolrDocumentList x = rsp.getResults();
System.out.println(rsp);
}
catch (SolrServerException e) {
e.printStackTrace();
}
}
}
我編譯使用
d這個代碼我的servlet代碼:\ XAMPP \ tomcat的\的webapps \例子\ WEB -INF \ classes> javac -classpath。; D:\ JAR \ servl et-api.jar; D:\ JAR \ 1solr-core-1.3.0.jar; D:\ JAR \ 1solr-solrj-1.3.0 .jar; D:\ JAR \ 1solr -common-1.3.0.jar; D:\ JAR \ apache-solr-solrj-1.4.0.jar HelloWorldExample.java
此代碼編譯沒有問題。然而,當我運行這個servlwt它給了我一個錯誤:
type Exception report message
description The server encountered an internal error() that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception root cause
java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/impl/CommonsHttpSolrServer HelloWorldExample.doGet(HelloWorldExample.java:35) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
開始閱讀。 http://stackoverflow.com/search?q=%5Bjava%5D+NoClassDefFoundError –
我一直在嘗試從最近3小時進行調試...請建議 – CodeMonkey
在您的課程路徑中添加solr jar文件 – Sap