我正在使用 JavaExec 任务来运行不同的类,但是每当我尝试使用 运行其中一个任务gradle <task>
时,我都会收到一条错误消息Error: JavaFX runtime components are missing, and are required to run this application
。
如果我只是设置mainClassName='exercise1.Cards'
或其他任何类名,运行gradle run
完全正常。我猜想在使用 JavaExec 运行类时找不到 JavaFX 类,我想知道如何包含它们。
构建.gradle:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
javafx {
modules = [ 'javafx.controls' ]
}
task runExercise1(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'exercise1.Cards'
}
task runExercise2(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'exercise2.InvestmentCalculator'
}
task runExercise3(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'exercise3.PointCircle'
}
task runExercise4(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'exercise4.OccurrenceHistogram'
}