title: Running Jar from command line: ClassNotFoundException
body: <p>I'm using ANT for creating a JAR file of my application. As I read, I should put the external Jars I need as arguments from the command line, but I want to build a Manifest file.</p>
  
  <p>This is my build.xml file (only the part in which I build the jar)</p>
  
  <pre><code>&lt;!-- Build jar from classes --&gt;
      &lt;target name="jar" depends="compile" description="Build a jar file."&gt;
           &lt;manifestclasspath property="jar.classpath" jarfile="${target.build.main}/main"&gt;
               &lt;classpath&gt;
                   &lt;fileset dir="${target.build.main}/lib" includes="*.jar"/&gt;
               &lt;/classpath&gt;
           &lt;/manifestclasspath&gt;
  &lt;jar destfile="${target.dist}/configuration-deployer.jar" basedir="${target.build.main}"&gt;
          &lt;manifest&gt;
              &lt;attribute name="Main-Class" value="${dist.main.class}" /&gt;
              &lt;attribute name="Class-Path" value="${jar.classpath}" /&gt;
          &lt;/manifest&gt;
      &lt;/jar&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>Now this is an extract of the manifest file</p>
  
  <pre><code>Manifest-Version: 1.0
  Ant-Version: Apache Ant 1.8.4
  Created-By: 1.6.0_45-b06 (Sun Microsystems Inc.)
  Main-Class: com.sap.coas.deployer.StoreInstanceOnMove
  Class-Path: lib/ConfigurationMetamodel-1.jar lib/Consumer_api-1.jar li
  b/FunctionalSystemMetaModel-1.jar lib/WS_api-1.jar lib/activemq-core-
  5.7.0.jar lib/activemq-protobuf-1.1.jar ..... other jar
  </code></pre>
  
  <p>If I open the JAR generated, I can see the manifest inside META-INF folder, and the lib folder containes all the libraries.
  So the structure of the JAR is this one:</p>
  
  <pre><code>/META-INF/manifest.mf
  /lib/ConfigurationMetamodel-1.jar
  /lib/otherJar.jar ........
  </code></pre>
  
  <p>But when I try to run</p>
  
  <pre><code>java -jar myJar.jar
  </code></pre>
  
  <p>I got the ClassNotFoundException, and I'm sure that the jar containing the class that throw the exception is in the lib folder.</p>
  
  <p>Thanks!</p>