title: Java class is present in classpath but startup fails with Error: Could not find or load main class
body: <p>I have a jar file <code>foobar.jar</code> containing the following two classes:</p>
  
  <pre><code>public class Foo {
  
      public static void main(String[] args) {
          System.out.println("Foo");
      }
  }
  </code></pre>
  
  <p>The other class looks like this:</p>
  
  <pre><code>import javax.batch.api.chunk.ItemProcessor;
  
  public class Bar implements ItemProcessor {
  
      public static void main(String[] args) {
          System.out.println("Bar");
      }
  
      @Override
      public Object processItem(Object item) throws Exception {
          return item;
      }
  }
  </code></pre>
  
  <p>If I execute the program using the following command, the program behaves as expected and prints <code>Foo</code>:</p>
  
  <pre><code>$ java -cp foobar.jar Foo
  Foo
  $ 
  </code></pre>
  
  <p>But if I try to start the program using the main method in the class <code>Bar</code>, the JVM prints a startup error and exits:</p>
  
  <pre><code>$ java -cp foobar.jar Bar
  Error: Could not find or load main class Bar
  $
  </code></pre>
  
  <p>This is the same error as if I would try to start the program using a class which is not in the jar, e.g.</p>
  
  <pre><code>$ java -cp foobar.jar BarNotThere
  Error: Could not find or load main class BarNotThere
  $
  </code></pre>
  
  <p>Why do I get this error? The fact that the <code>Foo.main</code> method can be started and I'm able to decompile the class <code>Bar</code> from the jar proves, that the class should be available on the classpath. I realize that this could have something to do with the interface <code>ItemProcessor</code> not being on the classpath. But shouldn't I get a <code>java.lang.ClassNotFoundException</code> in that case?</p>