线程中的Kotlin KTOR异常。 Noclassdeffounderror

发布于 2025-01-23 23:56:12 字数 3220 浏览 0 评论 0原文

我是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文