我正在通过gradle运行JavaFX 11(TornadoFX 2.0.0-RC1)应用程序,但是每次我使用run任务时,都会收到“找不到模块”或“找不到或加载主类”的信息。错误。
当我在构建之前运行干净时,它可以正常工作,但是在随后的构建中,我再次得到错误,直到我再次运行干净为止。必须在每次构建之前运行干净,这非常耗时,因此我希望有一种解决方案可以正确消除错误。
14:34:30: Executing task 'run'...
> Configure project :STTSim-TornadoFX
Found module name 'STTSim.TornadoFX'
> Task :STTSim-TornadoFX:compileKotlin
> Task :STTSim-TornadoFX:compileJava
> Task :STTSim-TornadoFX:processResources UP-TO-DATE
> Task :STTSim-TornadoFX:classes
> Task :STTSim-TornadoFX:run FAILED
WARNING: module-info.class ignored in patch: D:\OneDrive\Hot Storage\Coding\Java\Personal\STTSim\STTSim-TornadoFX\build\classes\kotlin\main
Error: Could not find or load main class com.genguava.sttsim.app.SimApp in module STTSim.TornadoFX
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':STTSim-TornadoFX:run'.
> Process 'command 'C:\Program Files\Java\jdk-11.0.1\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
4 actionable tasks: 3 executed, 1 up-to-date
Process 'command 'C:\Program Files\Java\jdk-11.0.1\bin\java.exe'' finished with non-zero exit value 1
14:34:33: Task execution finished 'run'.
val tornadoFXVersion: String by project
plugins {
application
id("org.openjfx.javafxplugin") version "0.0.7"
}
repositories {
}
dependencies {
implementation("no.tornado:tornadofx:$tornadoFXVersion")
implementation("com.google.code.gson:gson:2.8.5")
implementation("org.hildan.fxgson:fx-gson:3.1.2")
implementation("org.jsoup:jsoup:1.11.3")
}
application {
mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp"
applicationDefaultJvmArgs = listOf(
"--add-opens=javafx.controls/javafx.scene.control=tornadofx",
"--add-opens=javafx.controls/javafx.scene.control.skin=tornadofx",
"--add-opens=javafx.graphics/javafx.scene=tornadofx"
)
}
javafx {
modules = listOf("javafx.controls", "javafx.media", "javafx.web", "javafx.swing", "javafx.fxml")
version = "11.0.1"
}
/*
tasks.withType(JavaCompile::class) {
options.compilerArgs.add("--add-modules=java.sql")
}
*/
tasks.jar {
manifest {
attributes(mapOf("Class-Path" to configurations.runtimeClasspath.map { it.asPath }, "Main-Class" to application.mainClassName))
}
from(configurations.compile.map { entry -> zipTree(entry) }) {
exclude("META-INF/MANIFEST.MF")
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
}
}
sourceSets {
main {
output.setResourcesDir(File("build/classes/kotlin/main")) // dodgy workaround
}
}
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
java
}
buildscript {
val kotlinVersion: String by project
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
}
}
allprojects {
val junitVersion: String by project
repositories {
mavenLocal()
mavenCentral()
}
apply(plugin = "kotlin")
apply(plugin = "org.junit.platform.gradle.plugin")
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
}
tasks.named<KotlinCompile>("compileKotlin") {
kotlinOptions.jvmTarget = "1.8"
}
}
答案 0 :(得分:2)
似乎未应用module-info.class
,这可能导致缺乏定义,mainClassName
是什么。进行此模块构建可能是进行项目构建的前提。
mainClassName = "STTSim.TornadoFX/com.genguava.sttsim.app.SimApp"
可能无效。