title: How to run a class from Jar which is not the Main-Class in its Manifest file
body: <p>I have a JAR with 4 classes, each one has Main method. I want to be able to run each one of those as per the need. I am trying to run it from command-line on Linux box.</p>
  
  <pre><code>E.g. The name of my JAR is MyJar.jar
  </code></pre>
  
  <p>It has directory structure for the main classes as follows: </p>
  
  <pre><code>com/mycomp/myproj/dir1/MainClass1.class
  com/mycomp/myproj/dir2/MainClass2.class
  com/mycomp/myproj/dir3/MainClass3.class
  com/mycomp/myproj/dir4/MainClass4.class
  </code></pre>
  
  <p>I know that I can specify one class as main in my Manifest file. But is there any way by which I can specify some argument on command line to run whichever class I wish to run?</p>
  
  <p>I tried this:</p>
  
  <pre><code>jar cfe MyJar.jar com.mycomp.myproj.dir2.MainClass2 com/mycomp/myproj/dir2/MainClass2.class /home/myhome/datasource.properties /home/myhome/input.txt
  </code></pre>
  
  <p>And I got this error:</p>
  
  <pre><code>com/mycomp/myproj/dir2/MainClass2.class : no such file or directory
  </code></pre>
  
  <p>(In the above command, '/home/myhome/datasource.properties' and '/home/myhome/input.txt' are the command line arguments).</p>