线程中的Kotlin KTOR异常。 Noclassdeffounderror
我是KTOR的新手。
我开发了简单的应用程序,我想
在这里运行它是我的main
函数,
fun main() {
embeddedServer(
factory = CIO,
port = 8080,
host = "0.0.0.0",
module = {
install(ContentNegotiation) {
json()
}
configureDependencyInjection()
configureCategoryRouting()
configureImageRouting()
Database.connect(
url = "jdbc:postgresql://localhost:5432/postgres",
driver = "org.postgresql.Driver",
user = "xxxxxxxx",
password = "xxxxxxxxxx"
)
transaction {
SchemaUtils.create(Categories, Images)
}
}
).start(
wait = true
)
}
我确实在Linux中使用此命令构建了一个JAR文件 ./ gradlew installdist
这是我的build> build.gradle.kts
val ktorVersion: String by project
val kotlinVersion: String by project
val logbackVersion: String by project
val exposedVersion: String by project
val koinVersion: String by project
plugins {
application
kotlin("jvm") version "1.6.20"
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.20"
id("com.github.johnrengelman.shadow") version "7.0.0"
}
group = "wallpaper.io"
version = "0.0.1"
application {
mainClass.set("wallpaper.io.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap") }
}
tasks.withType<Jar> {
manifest {
attributes["Main-class"] = "wallpaper.io.ApplicationKt"
}
}
dependencies {
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-html-builder-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-cio-jvm:$ktorVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.insert-koin:koin-ktor:$koinVersion")
implementation("io.insert-koin:koin-logger-slf4j:$koinVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.postgresql:postgresql:42.3.3")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
}
当我使用此命令java -jar wallpaper-backend-0.0.0.1.jar
时我知道
Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/server/cio/CIO
at wallpaper.io.ApplicationKt.main(Application.kt:19)
at wallpaper.io.ApplicationKt.main(Application.kt)
我的问题是什么?
I'm new to ktor.
I developed simple app and I want to run it
here is my main
function
fun main() {
embeddedServer(
factory = CIO,
port = 8080,
host = "0.0.0.0",
module = {
install(ContentNegotiation) {
json()
}
configureDependencyInjection()
configureCategoryRouting()
configureImageRouting()
Database.connect(
url = "jdbc:postgresql://localhost:5432/postgres",
driver = "org.postgresql.Driver",
user = "xxxxxxxx",
password = "xxxxxxxxxx"
)
transaction {
SchemaUtils.create(Categories, Images)
}
}
).start(
wait = true
)
}
I did Build a Jar file with this command in linux./gradlew installDist
here is my build.gradle.kts
val ktorVersion: String by project
val kotlinVersion: String by project
val logbackVersion: String by project
val exposedVersion: String by project
val koinVersion: String by project
plugins {
application
kotlin("jvm") version "1.6.20"
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.20"
id("com.github.johnrengelman.shadow") version "7.0.0"
}
group = "wallpaper.io"
version = "0.0.1"
application {
mainClass.set("wallpaper.io.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap") }
}
tasks.withType<Jar> {
manifest {
attributes["Main-class"] = "wallpaper.io.ApplicationKt"
}
}
dependencies {
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-html-builder-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-cio-jvm:$ktorVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.insert-koin:koin-ktor:$koinVersion")
implementation("io.insert-koin:koin-logger-slf4j:$koinVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.postgresql:postgresql:42.3.3")
implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
}
when i use this command java -jar Wallpaper-Backend-0.0.1.jar
i get this error
Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/server/cio/CIO
at wallpaper.io.ApplicationKt.main(Application.kt:19)
at wallpaper.io.ApplicationKt.main(Application.kt)
any idea what is my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论