如何修复';未指定端口或sslPort';在gradle/kotlin/netty项目中由io.ktor.server.engine.CommandLineKt抛出?
我根据此处的教程创建了以下文件: 这是我的kotlin文件:如何修复';未指定端口或sslPort';在gradle/kotlin/netty项目中由io.ktor.server.engine.CommandLineKt抛出?,gradle,kotlin,ktor,Gradle,Kotlin,Ktor,我根据此处的教程创建了以下文件: 这是我的kotlin文件: package blog import io.ktor.application.* import io.ktor.http.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* fun Application.main() { install(Def
package blog
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
fun Application.main() {
install(DefaultHeaders)
install(CallLogging)
install(Routing) {
get("/") {
call.respondText("My Example Blog2", ContentType.Text.Html)
}
}
}
这是我的build.gradle文件的内容
group 'Example'
buildscript {
ext.kotlin_version = '1.3.61'
ext.ktor_version = '1.3.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'io.ktor.server.netty.EngineMain'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.3"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
和application.conf
ktor {
deployment {
port = 8080
}
application {
modules = [ blog.BlogAppKt.main ]
}
}
他们都生活在同一个文件夹中
当我试图通过此命令/gradlew run
运行服务器时,收到以下错误消息:
> Task :run FAILED
Exception in thread "main" java.lang.IllegalArgumentException: Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
at io.ktor.server.engine.CommandLineKt$commandLineEnvironment$environment$1.invoke(CommandLine.kt:129)
at io.ktor.server.engine.CommandLineKt$commandLineEnvironment$environment$1.invoke(CommandLine.kt)
at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.build(ApplicationEngineEnvironment.kt:105)
at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:44)
at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:57)
at io.ktor.server.netty.EngineMain.main(EngineMain.kt:21)
在这种情况下,如何使Netty进程可以看到
application.conf
?我需要将其添加到build.gradle
文件中
基本上,我需要明确地告诉gradle我的源文件和资源文件在哪里
sourceSets {
main.kotlin.srcDirs = [ 'src/main/kotlin' ]
main.resources.srcDirs = [ 'src/main/resource' ]
}
也许这个问题可以帮助你-它没有帮助。这是Intellij IDEA的解决方案(使用IDEA插件ktor)