How to make executable jar?


(Igor Lunin) #1

I have next gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
  sourceCompatibility = 1.7
targetCompatibility = 1.7
group = "i.lunin"
version = '1.0'
mainClassName = "i.lunin.Main"
eclipse.classpath.downloadJavadoc = true
  def javaFxHome = "${System.properties['java.home']}";
// JavaFX Ant builder library
def antJavaFxJar = "$javaFxHome/../lib/ant-javafx.jar"
  jar {
  manifest {
    attributes 'Implementation-Title': 'Auto Poster', 'Implementation-Version': version,
    'Main-Class' : mainClassName, 'Class-Path': 'libs/', 'Created-By': 'jdk1.7.0_11 (Sun Microsystems Inc.)'
  }
}
  repositories { mavenCentral() }
  dependencies {
  // JavaFX SDK library
  compile files("$javaFxHome/lib/jfxrt.jar")
  // Selenium library
  compile 'org.seleniumhq.selenium:selenium-java:2.29.0'
  // Geb library
  compile 'org.codehaus.geb:geb-core:0.7.2'
  compile 'org.codehaus.groovy:groovy-all:2.1.0'
}
  test { systemProperties 'property': 'value' }
  uploadArchives {
  repositories { flatDir { dirs 'repos' }
}
  copy {
    from 'posters'
    into 'repos/posters'
  }
  copy {
    from 'config.properties'
    into 'repos'
  }
  copy {
    from configurations.runtime
    into 'repos/libs'
  }
}

When i run it from eclipse (:clean, :assemble, :uploadArchives, :run) it’s starts good. But when i trying start this from cmd (D:\workspace\AutoPoster\repos>java AutoPoster-1.0), it write me next: “Error: Could not find or load main class AutoPoster-1.0”

I want to write gralde settings for executable jar.