I am just trying to invoke the basic Lucene demo class from a servlet and am getting this exception:
SEVERE: Servlet.service() for servlet SearcServlet threw exception
java.lang.ClassNotFoundException: org.apache.lucene.store.Directory
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at servlet.SearcServlet.doPost(SearcServlet.java:50)
My servlet method:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
try {
String[] arguments = new String[] {"123"};
SearchFiles.main(arguments);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The search is getting executed when i call it from another Java class, but when I do it from a servlet I get this exception. I am using the lucene demo search class, no other functionality included.
java.lang.ClassNotFoundExceptionis related to Java Classpath.ClassNotFoundExceptioncomes when JVM tries to load a class at runtime dynamically and if that class is not found in classpath it throwsjava.lang.ClassNotFoundException.As, you are using third party API called Apache Lucene, you need to place all required jar files to application classpath.
For a web application default classpath is
/WEB-INF/libdirectory under webapp or WebContent directory.Copy all required jar files there, eclipse takes care everything rest.