Home > database >  ktor execute jar file
ktor execute jar file

Time:04-13

I want make a jar file from my ktor project.

here is my main function

import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

fun main() {
embeddedServer(Netty, port = 8080, host = "0.0.0.0") {
    routing {
        get("/") {
            call.respondText("Hello World!")
        }
      }
   }.start(wait = true)
}

and here is my build.gradle

plugins {
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.6.20'
}

group "com.example"
version "0.0.1"
mainClassName = "com.example.ApplicationKt"

def isDevelopment = project.ext.has("development")
applicationDefaultJvmArgs = ["-Dio.ktor.development=$isDevelopment"]

application {
mainClass.set("io.ktor.server.netty.EngineMain")
}

repositories {
mavenCentral()
maven { url "https://maven.pkg.jetbrains.space/public/p/ktor/eap" }
}

dependencies {
implementation "io.ktor:ktor-server-core-jvm:$ktor_version"
implementation "io.ktor:ktor-server-netty-jvm:$ktor_version"
implementation "ch.qos.logback:logback-classic:$logback_version"
testImplementation "io.ktor:ktor-server-tests-jvm:$ktor_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}

and here is my settings.gradle

rootProject.name = "ktor-sample"

when I try to run ./gradlew :ktor-sample:installDist I get this error

  • What went wrong: Project 'ktor-sample' not found in root project 'ktor-sample'.

  • 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.

CodePudding user response:

I guess you don't have a subproject named ktor-sample so just run ./gradlew installDist.

  • Related