1

我有下一个示例(来自 groovyfx 站点),它是一个简单的窗口。

import static groovyx.javafx.GroovyFX.start

start {
  stage(title: 'GroovyFX Hello World', visible: true) {
    scene(fill: BLACK, width: 700, height: 250) {
      hbox(padding: 60) {
        text(text: 'Groovy', font: '80pt sanserif') {
          fill linearGradient(endX: 0, stops: [PALEGREEN, SEAGREEN])
        }
        text(text: 'FX', font: '80pt sanserif') {
          fill linearGradient(endX: 0, stops: [CYAN, DODGERBLUE])
          effect dropShadow(color: DODGERBLUE, radius: 25, spread: 0.25)
        }
      }
    }
  }
}

如何运行它gradle run

我的build.gradle

 apply plugin: 'groovy'

 sourceCompatibility = 1.8
 targetCompatibility = 1.8

 project.ext.set('javafxHome', System.env['JAVAFX_HOME'])

 repositories {
   mavenCentral()
 }

 configurations {
   ivy
 }

 dependencies {
   ivy "org.apache.ivy:ivy:2.3.0"
   compile 'org.codehaus.groovy:groovy-all:2.3.6'
   compile 'org.codehaus.groovyfx:groovyfx:0.4.0'
   compile files("${javafxHome}/rt/lib/jfxrt.jar")
 }


tasks.withType(GroovyCompile) {
  groovyClasspath += configurations.ivy
}

我可能会从 IDE 运行它,但是如何使用 cli 运行它,然后使用 Main 类的路径构建 jar?

4

1 回答 1

1

它适用于以下配置。

结构:

  • 构建.gradle
  • 源/
    • 主要的
      • 时髦的
        • 主程序

构建.gradle

apply plugin: 'groovy'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
  mavenCentral()
}

configurations {
  ivy
}

dependencies {
  ivy "org.apache.ivy:ivy:2.3.0"
  compile 'org.codehaus.groovy:groovy-all:2.3.6'
  compile 'org.codehaus.groovyfx:groovyfx:0.4.0'
  compile files("${System.getenv('JAVA_HOME')}/jre/lib/ext/jfxrt.jar")
}

tasks.withType(GroovyCompile) {
  groovyClasspath += configurations.ivy
}

task run(type: JavaExec) {
    main = 'Main'
    classpath sourceSets.main.runtimeClasspath
}

主程序

import static groovyx.javafx.GroovyFX.start

start {
  stage(title: 'GroovyFX Hello World', visible: true) {
    scene(fill: BLACK, width: 700, height: 250) {
      hbox(padding: 60) {
        text(text: 'Groovy', font: '80pt sanserif') {
          fill linearGradient(endX: 0, stops: [PALEGREEN, SEAGREEN])
        }
        text(text: 'FX', font: '80pt sanserif') {
          fill linearGradient(endX: 0, stops: [CYAN, DODGERBLUE])
          effect dropShadow(color: DODGERBLUE, radius: 25, spread: 0.25)
        }
      }
    }
  }
}

你已经看过这个网站了吗?

于 2014-09-16T09:07:32.240 回答