title: Running a Gradle compiled Java application with dependencies via the java command
body: <p>I’m trying to compile the Code Example 3 from <a href="http://www.oracle.com/technetwork/articles/javase/index-141957.html" rel="nofollow">this article explaining the Swing Application Framework (JSR 296)</a> with <a href="http://gradle.org/" rel="nofollow">Gradle</a> and to run it from the command line with the <code>java</code> command.</p>
  
  <p>My directory layout looks like this:</p>
  
  <pre><code>├── build.gradle
  └── src/
      └── main/
          └── java/
              └── demo/
                  └── BasicSingleFrameApp.java
  </code></pre>
  
  <p>The <code>build.gradle</code> file defines a dependency to the <code>appframework</code>:</p>
  
  <pre><code>apply plugin: 'java'
  
  repositories {
    mavenCentral()
  }
  
  dependencies {
    compile 'org.jdesktop:appframework:1.0.3'
  }
  </code></pre>
  
  <p>And this is the <code>BasicSingleFrameApp.java</code> file, a copy of the example of the article mentioned above, enhanced by a package declaration:</p>
  
  <pre><code>package demo;
  
  import org.jdesktop.application.*;
  import javax.swing.*;
  import java.awt.*;
  
  public class BasicSingleFrameApp extends SingleFrameApplication {
      JLabel label;
  
      @Override
      protected void startup() {
          getMainFrame().setTitle("BasicSingleFrameApp");
          label = new JLabel("Hello, world!");
          label.setFont(new Font("SansSerif", Font.PLAIN, 22));
          show(label);
      }
  
      public static void main(String[] args) {
          Application.launch(BasicSingleFrameApp.class, args);
      }
  
  }
  </code></pre>
  
  <p>Compiling with <code>gradle build</code> works fine and without errors.</p>
  
  <p>But when I then try to run the <code>BasicSingleFrameApp</code> with</p>
  
  <pre><code>$ java -cp build/classes/main/ demo.BasicSingleFrameApp
  </code></pre>
  
  <p>I get the error message:</p>
  
  <pre><code>Error: Could not find or load main class demo.BasicSingleFrameApp
  </code></pre>
  
  <p>When I replace the <code>BasicSingleFrameApp</code> class with a simple “Hello, world!” printing class without dependencies, everything works fine.</p>
  
  <p>I’m confused, because in my understanding I correctly set up the classpath and I don’t understand why the <code>main</code> method (which has the right signature) cannot be found.</p>
  
  <p>This is my Java version:</p>
  
  <pre><code>java version "1.8.0_20"
  Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
  Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
  </code></pre>
  
  <p>which I am running an Mac OS X Yosemite 10.10.2.</p>