Hello everyone, I am trying to get a <#C0A974TJ9|k...
# server
c
Hello everyone, I am trying to get a #ktor api server jar build, and i tried both documented options with shadowJar and simple gradle jar build, and in both cases when i try running the jar via java -jar jarname.jar i get the following error: Error: Could not find or load main class io.ktor.server.netty.EngineMain. Could somebody please point me in the right direction how I can get the jar built and working ? In IntelliJ the server runs ok.
v
sounds like a
build.gradle
misconfiguration, can you share yours?
I recently built a ktor fat jar with the following
build.gradle.kts
task, however using a plugin (like shadowJar) sounds like a rather better solution
Copy code
tasks.withType<Jar> {
    manifest {
        attributes["Main-Class"] = "mira.MainKt"
    }

    from(configurations.runtimeClasspath.get()
        .onEach { println("add from dependencies: ${it.name}") }
        .map { if (it.isDirectory) it else zipTree(it) })
    val sourcesMain = sourceSets.main.get()
    sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
    from(sourcesMain.output)

}
e
Try using the application plugin and specify the main class there:
Copy code
plugins {
    application
}

application {
    mainClassName = "your.package.MainKt"
}
If you then get an error about missing dependencies like the Kotlin Intrinsics library you may want to look at the shadow plugin, which will bundle all your dependencies into your built JAR: https://imperceptiblethoughts.com/shadow/introduction/