ktor
ktor copied to clipboard
Ktor does not detect my application.conf file
build.gradle file:
group 'Example'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.51'
ext.ktor_version = '0.9.0'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'com.WebAppKt'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
repositories {
mavenCentral()
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/ktor" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "io.ktor:ktor-server-jetty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.1"
}
File structure:
application.conf:
ktor {
deployment {
port = 9000
watch = [ com ]
}
application {
modules = [ com.WebAppKt.main ]
}
}
The log:
7:47:45 PM: Executing task 'run'...
:compileKotlin UP-TO-DATE
:compileJava NO-SOURCE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
19:47:47.236 [main] DEBUG org.eclipse.jetty.util.log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog
19:47:47.253 [main] INFO org.eclipse.jetty.util.log - Logging initialized @502ms to org.eclipse.jetty.util.log.Slf4jLog
19:47:47.264 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.Server@19bb089b added {qtp897913732{STOPPED,8<=0<=200,i=0,q=0},AUTO}
19:47:47.286 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - HttpConnectionFactory@36d64342[HTTP/1.1] added {HttpConfiguration@39ba5a14{32768/8192,8192/8192,https://:0,[]},POJO}
19:47:47.376 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - HTTP2CServerConnectionFactory@735b5592[h2c] added {HttpConfiguration@39ba5a14{32768/8192,8192/8192,https://:0,[]},POJO}
19:47:47.388 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{null,[]}{0.0.0.0:0} added {org.eclipse.jetty.server.Server@19bb089b,UNMANAGED}
19:47:47.389 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{null,[]}{0.0.0.0:0} added {qtp897913732{STOPPED,8<=0<=200,i=0,q=0},AUTO}
19:47:47.390 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{null,[]}{0.0.0.0:0} added {org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@475530b9,AUTO}
19:47:47.390 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{null,[]}{0.0.0.0:0} added {org.eclipse.jetty.io.ArrayByteBufferPool@59fa1d9b,POJO}
19:47:47.391 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{null,[http/1.1]}{0.0.0.0:0} added {HttpConnectionFactory@36d64342[HTTP/1.1],AUTO}
19:47:47.392 [main] DEBUG org.eclipse.jetty.server.AbstractConnector - ServerConnector@d8355a8{HTTP/1.1,[http/1.1]}{0.0.0.0:0} added HttpConnectionFactory@36d64342[HTTP/1.1]
19:47:47.392 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:0} added {HTTP2CServerConnectionFactory@735b5592[h2c],AUTO}
19:47:47.393 [main] DEBUG org.eclipse.jetty.server.AbstractConnector - ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:0} added HTTP2CServerConnectionFactory@735b5592[h2c]
19:47:47.398 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:0} added {org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@523884b2,MANAGED}
19:47:47.399 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.Server@19bb089b added {ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080},AUTO}
19:47:47.416 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.Server@19bb089b added {io.ktor.server.jetty.JettyKtorHandler@464bee09,MANAGED}
19:47:47.416 [main] INFO ktor.application - No ktor.deployment.watch patterns specified, automatic reload is not active
19:47:47.461 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.server.Server@19bb089b
19:47:47.463 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.Server@19bb089b added {org.eclipse.jetty.server.handler.ErrorHandler@6c3708b3,AUTO}
19:47:47.465 [main] INFO org.eclipse.jetty.server.Server - jetty-9.4.6.v20170531
19:47:47.485 [main] DEBUG org.eclipse.jetty.server.handler.AbstractHandler - starting org.eclipse.jetty.server.Server@19bb089b
19:47:47.485 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting qtp897913732{STOPPED,8<=0<=200,i=0,q=0}
19:47:47.487 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @739ms qtp897913732{STARTED,8<=8<=200,i=1,q=0}
19:47:47.487 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting io.ktor.server.jetty.JettyKtorHandler@464bee09
19:47:47.487 [main] DEBUG org.eclipse.jetty.server.handler.AbstractHandler - starting io.ktor.server.jetty.JettyKtorHandler@464bee09
19:47:47.488 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @740ms io.ktor.server.jetty.JettyKtorHandler@464bee09
19:47:47.488 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.server.handler.ErrorHandler@6c3708b3
19:47:47.488 [main] DEBUG org.eclipse.jetty.server.handler.AbstractHandler - starting org.eclipse.jetty.server.handler.ErrorHandler@6c3708b3
19:47:47.488 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @741ms org.eclipse.jetty.server.handler.ErrorHandler@6c3708b3
19:47:47.489 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080}
19:47:47.506 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080} added {sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:8080],POJO}
19:47:47.508 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@475530b9
19:47:47.509 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @761ms org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@475530b9
19:47:47.509 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting HttpConnectionFactory@36d64342[HTTP/1.1]
19:47:47.510 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @762ms HttpConnectionFactory@36d64342[HTTP/1.1]
19:47:47.510 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting HTTP2CServerConnectionFactory@735b5592[h2c]
19:47:47.511 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @763ms HTTP2CServerConnectionFactory@735b5592[h2c]
19:47:47.512 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@523884b2
19:47:47.537 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.io.ManagedSelector@22a67b4 id=0 keys=-1 selected=-1 added {EatWhatYouKill@57855c9a/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@3b084709/IDLE/0/1,AUTO}
19:47:47.538 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@523884b2 added {org.eclipse.jetty.io.ManagedSelector@22a67b4 id=0 keys=-1 selected=-1,AUTO}
19:47:47.539 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.io.ManagedSelector@3224f60b id=1 keys=-1 selected=-1 added {EatWhatYouKill@63e2203c/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@1efed156/IDLE/0/1,AUTO}
19:47:47.541 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@523884b2 added {org.eclipse.jetty.io.ManagedSelector@3224f60b id=1 keys=-1 selected=-1,AUTO}
19:47:47.541 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.io.ManagedSelector@22a67b4 id=0 keys=-1 selected=-1
19:47:47.542 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting EatWhatYouKill@57855c9a/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@3b084709/IDLE/0/1
19:47:47.542 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @794ms EatWhatYouKill@57855c9a/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@3b084709/IDLE/0/1
19:47:47.686 [main] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - queue org.eclipse.jetty.io.ManagedSelector$$Lambda$4/513169028@4d95d2a2
19:47:47.693 [qtp897913732-10] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - run org.eclipse.jetty.io.ManagedSelector$$Lambda$4/513169028@4d95d2a2
19:47:47.696 [qtp897913732-10] DEBUG org.eclipse.jetty.util.thread.strategy.EatWhatYouKill - EatWhatYouKill@57855c9a/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@3b084709/PRODUCING/0/1 execute true
19:47:47.698 [qtp897913732-10] DEBUG org.eclipse.jetty.util.thread.strategy.EatWhatYouKill - EatWhatYouKill@57855c9a/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@3b084709/PRODUCING/0/1 produce non-blocking
19:47:47.698 [qtp897913732-10] DEBUG org.eclipse.jetty.io.ManagedSelector - Selector loop waiting on select
19:47:47.701 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @953ms org.eclipse.jetty.io.ManagedSelector@22a67b4 id=0 keys=0 selected=0
19:47:47.703 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting org.eclipse.jetty.io.ManagedSelector@3224f60b id=1 keys=-1 selected=-1
19:47:47.703 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - starting EatWhatYouKill@63e2203c/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@1efed156/IDLE/0/1
19:47:47.703 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @956ms EatWhatYouKill@63e2203c/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@1efed156/IDLE/0/1
19:47:47.705 [main] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - queue org.eclipse.jetty.io.ManagedSelector$$Lambda$4/513169028@53f65459
19:47:47.705 [qtp897913732-11] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - run org.eclipse.jetty.io.ManagedSelector$$Lambda$4/513169028@53f65459
19:47:47.705 [qtp897913732-11] DEBUG org.eclipse.jetty.util.thread.strategy.EatWhatYouKill - EatWhatYouKill@63e2203c/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@1efed156/PRODUCING/0/1 execute true
19:47:47.705 [qtp897913732-11] DEBUG org.eclipse.jetty.util.thread.strategy.EatWhatYouKill - EatWhatYouKill@63e2203c/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@1efed156/PRODUCING/0/1 produce non-blocking
19:47:47.705 [qtp897913732-11] DEBUG org.eclipse.jetty.io.ManagedSelector - Selector loop waiting on select
19:47:47.706 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @958ms org.eclipse.jetty.io.ManagedSelector@3224f60b id=1 keys=0 selected=0
19:47:47.706 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @959ms org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@523884b2
19:47:47.711 [main] DEBUG org.eclipse.jetty.util.component.ContainerLifeCycle - ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080} added {acceptor-0@74650e52,POJO}
19:47:47.713 [main] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - queue acceptor-0@74650e52
19:47:47.714 [qtp897913732-12] DEBUG org.eclipse.jetty.util.thread.QueuedThreadPool - run acceptor-0@74650e52
19:47:47.716 [main] INFO org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080}
19:47:47.717 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @969ms ServerConnector@d8355a8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:8080}
19:47:47.717 [main] INFO org.eclipse.jetty.server.Server - Started @970ms
19:47:47.718 [main] DEBUG org.eclipse.jetty.util.component.AbstractLifeCycle - STARTED @970ms org.eclipse.jetty.server.Server@19bb089b
The server still uses the port 8080 instead of 9000 and auto-reload doesn't work. I tried to rebuild the project many times.
Which one of the three shown application.conf is shown above with port 9000? I guess you just need one application.conf, which is usually placed in resources.
Yes, indeed looks like you've put to many configuration files out there. The one in src/main/resources should be used
Did you have your issue resolved?
It've not been resolved yet (I've removed other configuration file as you suggested) but I think the problem comes from my Main class:
fun main(args: Array<String>) {
embeddedServer(Netty) {
routing {
get("/") {
call.respondText("Hello, world!", ContentType.Text.Html)
}
}
}.start(wait = true)
}
In your ktor-samples-embedded, the config file path is pass into the args like this:
(getTasksByName("run", false).first() as JavaExec).args('-config=embedded.conf')
embeddedServer(Jetty, commandLineEnvironment(args)).start()
I tried to feed the args into the embeddedServer func as your "ktor-samples-embedded" like this but it doesn't work:
I see, currently you can't have config-based application with lambda-based module. We need to think about how to make this possible.
Did you configure your run configurations accordingly to instructions on the website? Some online tutorials aren't up-to-date. Page is below http://ktor.io/servers/engine.html Remember to create a function named Application.main() (or any other name instead of main, but you will need to configure it accordingly) to run your server. I have a sample of a chat app made with ktor, you can check it on my repos. You can also check for the samples that are available on this very repo
this is how your main should look like when using embeddedServer()
and application.conf
fun main(args: Array<String>) {
embeddedServer(Netty, commandLineEnvironment(args)).start(wait = true)
}
Any update on this?
This issue has been automatically marked as stale because it has not had recent activity.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.