title: Run a JAR file from the command line and specify classpath
body: <p>I've compiled a <a href="http://en.wikipedia.org/wiki/JAR_%28file_format%29" rel="noreferrer">JAR</a> file and specified the Main-Class in the manifest (I used the Eclipse <em>Export</em> function). My dependencies are all in a directory labeled <code>lib</code>. I can't seem to get a straight answer on how to execute my JAR file while specifying it should use the <code>lib/*</code> as the classpath.</p>
  
  <p>I've tried:</p>
  
  <pre><code>]$ java -jar -cp .:lib/* MyJar.jar
  ]$ java -cp .:lib/* -jar MyJar.jar
  ]$ java -cp .:lib/* com.somepackage.subpackage.Main
  </code></pre>
  
  <p>etc...</p>
  
  <p>Each gives an error saying:</p>
  
  <blockquote>
    <p><code>Error: Could not find or load main class ....</code></p>
  </blockquote>
  
  <p>or gives the <code>NoClassDefFoundError</code> indicating the libraries are not being found.</p>
  
  <p>I even tried remaking the JAR file and included the <code>lib</code> directory and contents, but still no dice...</p>
  
  <p>How can I execute a JAR file from the command line and specify the classpath to use?</p>