title: Cannot read index directory created by lucene from a servlet
body: <p>I have been trying to implement a small retrieval system using Apache Lucene. The app works well when use console for i/o. But i want to make it a web baed app. I have already created and tested the index using simple a cosole based test program. My index is at "D:\index".  But as soon as call the same search method from within the Servlet it shoots tons of errors.</p>
  
  <p>Here is my Search class:</p>
  
  <pre><code>    package indexer;
      import java.io.File;
      import java.io.IOException;
      import org.apache.lucene.analysis.Analyzer;
      import org.apache.lucene.analysis.standard.StandardAnalyzer;
      import org.apache.lucene.document.Document;
      import org.apache.lucene.index.DirectoryReader;
      import org.apache.lucene.index.IndexReader;
      import org.apache.lucene.queryparser.classic.QueryParser;
      import org.apache.lucene.search.IndexSearcher;
      import org.apache.lucene.search.Query;
      import org.apache.lucene.search.ScoreDoc;
      import org.apache.lucene.search.TopDocs;
      import org.apache.lucene.store.FSDirectory;
      import org.apache.lucene.util.Version;
  
      import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
  
      public class Search {
      String index = "D:\\index";
      IndexReader reader;
       IndexSearcher searcher;
      Analyzer analyzer;
      QueryParser parser;
  
      // :Post-Release-Update-Version.LUCENE_XY:
  
      public Search() throws IOException  {
          index = "D:\\index";
          // IndexReader reader = DirectoryReader.open(FSDirectory.open(new
          // File(index)));
          reader = DirectoryReader.open(FSDirectory.open(new File(index)));
          searcher = new IndexSearcher(reader);
          analyzer = new StandardAnalyzer(Version.LUCENE_4_9);
          parser = new QueryParser(Version.LUCENE_4_9, "title", analyzer);
      }
  
      public String[] searchIndex(String queryString) throws IOException,
              ParseException,
              org.apache.lucene.queryparser.classic.ParseException {
  
          String[] ids = new String[10];
          int i=0;
              System.out.println("searching for: " + queryString);
              Query query = parser.parse(queryString);
              TopDocs results = searcher.search(query, 10);
              System.out.println("total hits: " + results.totalHits);
              ScoreDoc[] hits = results.scoreDocs;
              for (ScoreDoc hit : hits) {
                  Document doc = searcher.doc(hit.doc);
                  System.out.printf( hit.score+"   "+ doc.get("id")+" ");
                  ids[i]=doc.get("id");
                  i++;
              }
  
          // searcher.close();
          return  ids;
      }
  }
  </code></pre>
  
  <p>And Here is my Servlet from where I tried to call the Search.searchIndex(query) method</p>
  
  <pre><code>package SearcherServlets;
  
  import indexer.Search;
  import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.sun.org.apache.xerces.internal.impl.xpath.regex.ParseException;
  
  
  @WebServlet("/SearchWeb")
  public class SearchWeb extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      public SearchWeb() {
          super();
  
      }
  
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          Search search = new Search();
          try {
              search.searchIndex("Android");
          } catch (ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (org.apache.lucene.queryparser.classic.ParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      }
  
  }
  </code></pre>
  
  <p>And here are the exceptions</p>
  
  <pre><code>SEVERE: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Personal]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:188)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Personal]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      ... 6 more
  Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/queryparser/classic/ParseException
      at java.lang.Class.getDeclaredFields0(Native Method)
      at java.lang.Class.privateGetDeclaredFields(Class.java:2436)
      at java.lang.Class.getDeclaredFields(Class.java:1806)
      at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
      at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
      at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
      at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
      at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:403)
      at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:879)
      at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  Caused by: java.lang.ClassNotFoundException: org.apache.lucene.queryparser.classic.ParseException
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
      ... 20 more
  
  Jul 11, 2014 1:24:48 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
  INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [126] milliseconds.
  Jul 11, 2014 1:24:48 PM org.apache.catalina.core.ContainerBase startInternal
  SEVERE: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:188)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  
  Jul 11, 2014 1:24:48 PM org.apache.catalina.startup.Catalina start
  SEVERE: The required Server component failed to start so Tomcat is unable to start.
  org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:689)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 7 more
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 9 more
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 11 more
  </code></pre>
  
  <p>I have not been able to figure out what is wrong.</p>