title: Turn multiple folders with Java code into runnable jar file
body: <p>I have some Java code on my machine that I run from the command line. I want to create a runnable <code>.jar</code> file from this code so that I can distribute my application more easily. </p>
  
  <p>The code is in four folders, called <code>fol_a</code>, <code>fol_b</code>, <code>fol_c</code>, and <code>fol_d</code>. Each of these contains a <code>/bin</code> subfolder, containing the <code>.class</code> files, and two of them (<code>fol_a</code> and <code>fol_b</code>) also contain a <code>/lib</code> folder, containing some <code>.jar</code> files that the code needs. </p>
  
  <p><code>fol_d</code> contains the class to run, <code>Demo</code>, which is in a package called <code>machineLearning</code>. The full path to the class is</p>
  
  <pre><code>fol_d/bin/machineLearning/Demo 
  </code></pre>
  
  <p>I currently run the code from the command line as follows:</p>
  
  <pre><code>$ cd fol_d/bin
  $ java -cp ".:../../fol_a/bin:../../fol_a/lib/*:../../fol_b/bin:../../fol_b/lib/*:../../fol_c/bin" machineLearning.Demo &lt;param_1&gt; &lt;param_2&gt; ... &lt;param_5&gt; 
  </code></pre>
  
  <p>where <code>&lt;param_1&gt;</code> to <code>&lt;param_5&gt;</code> are the arguments given to the <code>Main</code> method in <code>Demo</code>. </p>
  
  <p>What I want is to create one single <code>.jar</code> file that contains all the code that is necessary to execute <code>Demo</code> successfully, i.e., the code in <code>fol_a</code> through <code>fol_d</code>. I then want to be able to run this <code>.jar</code> file from the command line, giving it the arguments that go to the <code>Main</code> method in <code>Demo</code>. Something like this:</p>
  
  <pre><code>$ java -jar MyApplication.jar &lt;param_1&gt; ... &lt;param_5&gt;
  </code></pre>
  
  <p>Is this possible? How would I do this? I've been trying to find an answer online, but the amount of information confuses me.</p>
  
  <p>UPDATE</p>
  
  <p>Right! So it seems that all I needed to do was this:</p>
  
  <ul>
  <li>copy the contents of the <code>bin</code> directories to a new dir <code>myapp</code></li>
  <li>make a manifest.txt file that specifies the main class to run, as well as the classpath </li>
  <li>jar <code>myapp</code>: <code>$ jar cmf manifest.txt myapp.jar -C myapp/ .</code></li>
  <li>execute the jar: <code>$ java -jar myapp.jar &lt;arg_1&gt; &lt;arg_2&gt; ... &lt;arg_n&gt;</code></li>
  </ul>