https://kotlinlang.org logo
#ktor
Title
# ktor
u

亀窪翼

03/18/2024, 6:05 PM
Sorry, please tell me. When executing a ktor project made into a jar file, it does not accept a configuration file.
Copy code
ktor {
  deployment {
    port = 8080
  }
  application {
    modules = [ com.plugins.RoutingKt.configureRouting ]
  }
}
Copy code
java -jar /app/build/libs/app-0.0.1.jar -config=/app/src/main/resources/application.conf

SLF4J: No SLF4J providers were found.
2024-03-18T18:04:05.095166467Z SLF4J: Defaulting to no-operation (NOP) logger implementation
2024-03-18T18:04:05.095175467Z SLF4J: See <https://www.slf4j.org/codes.html#noProviders> for further details.
2024-03-18T18:04:05.109629884Z Exception in thread "main" java.lang.IllegalArgumentException: Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
2024-03-18T18:04:05.109770926Z 	at io.ktor.server.engine.CommandLineKt$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:78)
2024-03-18T18:04:05.109785259Z 	at io.ktor.server.engine.CommandLineKt$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:39)
2024-03-18T18:04:05.109797217Z 	at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.build(ApplicationEngineEnvironmentJvm.kt:74)
2024-03-18T18:04:05.110948301Z 	at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:48)
2024-03-18T18:04:05.110997926Z 	at io.ktor.server.engine.CommandLineKt.buildCommandLineEnvironment(CommandLine.kt:39)
2024-03-18T18:04:05.111004134Z 	at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:98)
2024-03-18T18:04:05.111008509Z 	at io.ktor.server.netty.EngineMain.main(EngineMain.kt:20)
2024-03-18T18:04:05.111012426Z 	at com.ApplicationKt.main(Application.kt:6)
Please tell me why this is happening.
Dockerfile
Copy code
FROM openjdk:21

RUN mkdir /app
WORKDIR /app

COPY . $WORKDIR
RUN cp /app/build/resources/main/application_local.conf /app/src/main/resources/application.conf
RUN chmod +x ./gradlew

EXPOSE 8080/tcp

ENTRYPOINT java -jar /app/build/libs/app-0.0.1.jar -config=/app/src/main/resources/application.conf
a

Aleksei Tirman [JB]

03/19/2024, 7:42 AM
Can you share the code of the
main
function?
u

亀窪翼

03/19/2024, 9:30 AM
@Aleksei Tirman [JB] Yes.This is
Application.kt
and
main
.
Copy code
package com

import io.ktor.server.netty.*

fun main(args: Array<String>) {
    EngineMain.main(args)
}
a

Aleksei Tirman [JB]

03/19/2024, 9:31 AM
Does it work when you run the application locally without Docker?
Also, please add the SLF4J logger implementation to see the logs.
u

亀窪翼

03/19/2024, 9:37 AM
I can't run the application locally.
Copy code
% java --version
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-58)
OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)
Copy code
% java -jar ./build/libs/app-0.0.1.jar -config=/Users/t/work/Kotlin/app/src/main/resources/application_local.conf
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See <https://www.slf4j.org/codes.html#noProviders> for further details.
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$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:78)
        at io.ktor.server.engine.CommandLineKt$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:39)
        at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.build(ApplicationEngineEnvironmentJvm.kt:74)
        at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:48)
        at io.ktor.server.engine.CommandLineKt.buildCommandLineEnvironment(CommandLine.kt:39)
        at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:98)
        at io.ktor.server.netty.EngineMain.main(EngineMain.kt:20)
        at com.ApplicationKt.main(Application.kt:6)
I try add the SLF4J logger.
Copy code
./gradlew run run --args="-config=/Users/t/work/Kotlin/app/src/main/resources/application_local.conf"

> Task :run
SLF4J(W): Class path contains multiple SLF4J providers.
SLF4J(W): Found provider [ch.qos.logback.classic.spi.LogbackServiceProvider@2ed94a8b]
SLF4J(W): Found provider [org.slf4j.reload4j.Reload4jServiceProvider@38082d64]
SLF4J(W): See <https://www.slf4j.org/codes.html#multiple_bindings> for an explanation.
SLF4J(I): Actual provider is of type [ch.qos.logback.classic.spi.LogbackServiceProvider@2ed94a8b]
2024-03-19 19:01:58.355 [main] INFO  Application - Autoreload is disabled because the development mode is off.
2024-03-19 19:02:00.263 [main] INFO  Application - Application started in 1.926 seconds.
2024-03-19 19:02:00.364 [DefaultDispatcher-worker-1] INFO  Application - Responding at <http://0.0.0.0:8080>
<==========---> 83% EXECUTING [21s]
> :run

> Task :run FAILED
I can run locally.
a

Aleksei Tirman [JB]

03/19/2024, 12:43 PM
I mean by using the
java
command.
u

亀窪翼

03/19/2024, 12:48 PM
OK. Sorry.I got the same error again.
Copy code
% cat ./src/main/resources/application_local.conf 
ktor {
  deployment {
    port = 8080
  }
  application {
    modules = [ com.plugins.RoutingKt.configureRouting ]
  }
}
Copy code
% java -jar ./build/libs/app-0.0.1.jar -config=./src/main/resources/application_local.conf
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See <https://www.slf4j.org/codes.html#noProviders> for further details.
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$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:78)
        at io.ktor.server.engine.CommandLineKt$buildCommandLineEnvironment$environment$1.invoke(CommandLine.kt:39)
        at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.build(ApplicationEngineEnvironmentJvm.kt:74)
        at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:48)
        at io.ktor.server.engine.CommandLineKt.buildCommandLineEnvironment(CommandLine.kt:39)
        at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:98)
        at io.ktor.server.netty.EngineMain.main(EngineMain.kt:20)
        at com.ApplicationKt.main(Application.kt:6)
a

Aleksei Tirman [JB]

03/19/2024, 12:59 PM
Please check that the
io.ktor:ktor-server-config-yaml
artifact isn't included. Otherwise, the server will try to load a YAML configuration.
u

亀窪翼

03/21/2024, 4:25 PM
Seriously, thank you. Thanks to you, it was solved.
5 Views