我项目的gradle/kotlin
目录结构遵循默认/推荐的方法:
MYPROJ
/src/main/kotlin
app/OnsetsWebapp.kt
这是build.gradle.kts:注意,我们指定了mainClassName = app.OnsetsWebapp
:plugins {
application
kotlin("jvm") version "1.3.71"
}
application {
mainClassName = "app.OnsetsWebapp"
}
dependencies {
compile(kotlin("stdlib"))
compile("org.slf4j:slf4j-simple:1.7.25")
compile("io.javalin:javalin:3.8.0")
compile("org.json:json:20160810")
compile("com.j2html:j2html:1.3.0")
}
repositories {
jcenter()
}
让我们来构建它:./gradlew build
BUILD SUCCESSFUL in 1s
8 actionable tasks: 5 executed, 3 up-to-date
现在运行它: $./gradlew run
这导致> Task :run FAILED
Error: Could not find or load main class app.OnsetsWebapp
Caused by: java.lang.ClassNotFoundException: app.OnsetsWebapp
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/java'' 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 0s
4 actionable tasks: 1 executed, 3 up-to-date
那么为什么找不到app.OnsetsWebapp
类呢? 最佳答案
我相信应该是:
申请{
mainClassName =“app.OnsetsWebappKt”
}
如果查看build/classes/kotlin/main/app
文件夹,则应该在其中看到两个类文件:OnsetsWebappKt
和OnsetsWebapp
。您想要一个带有Kt
后缀的