title: lucene main function not found
body: <p>I was running lucene library for my text analysis project (I am relatively new to java). There is problem with main function (or command).</p>
  
  <p>The lucene version I am using is 3.0.0, and is already compiled into a JAR file. The JAR file is in the same folder as the main class file Indexer.java.</p>
  
  <p>I first run the compile code:</p>
  
  <pre><code>javac -cp \lucene-core-3.0.0.jar Indexer.java
  </code></pre>
  
  <p>and it worked correctly and created the Indexer.class file in the same directory.</p>
  
  <p>Then I run the same sort of command:</p>
  
  <pre><code>java -cp \lucene-core.3.0.0.jar Indexer
  </code></pre>
  
  <p>This time the command line output says I don't have the main class Indexer:</p>
  
  <pre><code>could not find or load main class Indexer
  </code></pre>
  
  <p>I checked the original java code, there is main method defined:</p>
  
  <pre><code>import org.apache.lucene.index.*;
  
  import java.io.IOException;
  import java.io.File;
  
  
  import org.apache.lucene.store.Directory;
  import org.apache.lucene.store.FSDirectory;
  import org.apache.lucene.analysis.standard.*;
  import org.apache.lucene.util.Version;
  import org.apache.lucene.document.Document;
  import org.apache.lucene.document.Field;
  
  import java.io.FileReader;
  
  
  public class Indexer {
  
  private IndexWriter writer;
  
  private void indexFile(File f) throws Exception{
      System.out.println("Indexing " + f.getCanonicalPath());
      Document doc = getDocument(f);
      if(doc != null){
          writer.addDocument(doc);
      }
  }
  
  public Indexer(String IndexDir) throws IOException{
      Directory dir = FSDirectory.open(new File(IndexDir));
      writer = new IndexWriter(dir,new StandardAnalyzer(Version.LUCENE_30),
                                          true,IndexWriter.MaxFieldLength.UNLIMITED);
  }
  
  
  protected Document getDocument(File f) throws Exception{
      Document doc = new Document();
  
      doc.add(new Field("contents", new FileReader(f)));
      doc.add(new Field("filename",
                          f.getName(), 
                          Field.Store.YES,
                          Field.Index.NOT_ANALYZED));
      doc.add(new Field("fullpath",
                          f.getCanonicalPath(),
                          Field.Store.YES,
                          Field.Index.NOT_ANALYZED));
      return doc;
  }
  
  protected boolean acceptFile(File f){
      return f.getName().endsWith(".txt");
  }
  
  
  public int index(String dataDir) throws Exception{
  
      File[] files = new File(dataDir).listFiles();
  
  
      for(int i = 0; i &lt; files.length;i++){
          File f = files[i];
  
          if(!f.isDirectory() 
              &amp;&amp; !f.isHidden() 
              &amp;&amp; f.exists()
              &amp;&amp; f.canRead()
              &amp;&amp; acceptFile(f)){
              indexFile(f);
          }
      }
      return writer.numDocs();
  }
  
  public void close() throws IOException{
      writer.close();
  }
  
  public static void main(String[] args) throws Exception{
      if(args.length != 2){
          throw new Exception("Usage: java " + Indexer.class.getName()+" &lt;index dir&gt;&lt;data dir");
      }
  
      String indexDir = args[0];
      String dataDir = args[1];
  
      long start = System.currentTimeMillis();
      Indexer indexer = new Indexer(indexDir);
      int numIndexed = indexer.index(dataDir);
      indexer.close();
      long end = System.currentTimeMillis();
  
      System.out.println("Indexing " + 
              numIndexed + " files took " + (end-start)+ " milliseconds.");
  
  
  }
  
  }
  </code></pre>
  
  <p>What is wrong with my code/command?</p>