title: java.lang.NoClassDefFoundError - running a java file with external libraries
body: <p>I am new to java and have used it in netBeans but have never tried to compile or run it from terminal. So, my question may look naive. I have a directory of this structure:</p>
  
  <p><code>Folder X</code> contains:
  couple of files and a folder named <code>esa-lucene</code>.</p>
  
  <p><code>esa-lucene</code> is a directory having three folders <code>src, lib, web</code>:</p>
  
  <pre><code>.classpath, lib, .project, .settings, src, web
  </code></pre>
  
  <p>and I am trying to run a java file " <code>ESAWikipediaIndexer.java</code>" which exists in this subdirectory:</p>
  
  <pre><code>X/esa-lucene/src/edu/wiki/index/ESAWikipediaIndexer.java
  </code></pre>
  
  <p>I cd into <code>Folder X</code> and use this:</p>
  
  <pre><code>java -cp esa-lucene.jar edu.wiki.index.ESAWikipediaIndexer
  </code></pre>
  
  <p>But it gives me this error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: edu/wiki/index/ESAWikipediaIndexer
  Caused by: java.lang.ClassNotFoundException: edu.wiki.index.ESAWikipediaIndexer
      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  Could not find the main class: edu.wiki.index.ESAWikipediaIndexer. Program will exit.
  </code></pre>
  
  <p>also I've checked .classpath and it contains:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind="src" path="src"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/&gt;
      &lt;classpathentry kind="lib" path="lib/servlet-api.jar"/&gt;
      &lt;classpathentry kind="lib" path="web/WEB-INF/lib/lucene-analyzers-3.0.0.jar"/&gt;
      &lt;classpathentry kind="lib" path="web/WEB-INF/lib/lucene-core-3.0.0.jar"/&gt;
      &lt;classpathentry kind="lib" path="web/WEB-INF/lib/mysql-connector-java-5.1.12-bin.jar"/&gt;
      &lt;classpathentry kind="lib" path="web/WEB-INF/lib/trove-2.1.0.jar"/&gt;
      &lt;classpathentry kind="output" path="bin"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p>I've checked the <code>lib</code> and <code>web/WEB-INF/lib/</code> folders as well and all the required external libraries (jar files) also exist in this folder.</p>
  
  <p>I searched to find any solution and tried a couple of things but none of them worked. Have no clue how to make it work! </p>
  
  <p>BTW, apparently people have used this package before, and I just downloaded to use it too but wasn't successful so far.</p>