title: How to execute a main class in a jar from gradle using the 'java' command
body: <p>I have these files under the <code>&lt;project_root&gt;</code> folder:</p>
  
  <pre><code>./build.gradle
  ./build/libs/vh-1.0-SNAPSHOT.jar
  ./libs/groovy-all-2.1.7.jar
  ./src/main/groovy/vh/Main.groovy
  </code></pre>
  
  <p>In the <code>build.gradle</code> file, I have this task:</p>
  
  <pre><code>task vh( type:Exec ) {
      commandLine 'java -cp libs/groovy-all-2.1.7.jar:build/libs/' +
              project.name + '-' + version + '.jar vh.Main'
  }
  </code></pre>
  
  <p>The <code>Main.groovy</code> file is simple:</p>
  
  <pre><code>package vh
  
  class Main {
      static void main( String[] args ) {
          println 'Hello, World!'
      }
  
  }
  </code></pre>
  
  <p>After plugging in the string values, the command line is:</p>
  
  <pre><code>java -cp libs/groovy-all-2.1.7.jar:build/libs/vh-1.0-SNAPSHOT.jar vh.Main
  </code></pre>
  
  <p>If I run the command directly from shell, I get correct output. However, if I run <code>gradle vh</code>, it will fail. So, how do I make it work? Thank you very much.</p>