how do I pass a parameter from ```java -jar fat.ja...
# ktor
b
how do I pass a parameter from
Copy code
java -jar fat.jar --test="hi"
to KTOR so I can read inside my routes
1
a
One way is to pass environment variables and read them with
Java.lang.System.getenv
method:
Copy code
TEST=hi java -jar fat.jar
s
You could also the
-P
flag to create a custom config property, like mentioned at the bottom of this section: https://ktor.io/docs/configuration-file.html#command-line
👍 1
b
a related question: I've got this generated application.conf file
Copy code
ktor {
  deployment {
    port = 8080
  }
}

media {
    dir = "aadfsdf"
}
when I start the server inside intellij, environment.config.propertyOrNull("media.dir") is null
so from what I see, you could pass
Copy code
-P:media.dir=/data
to override this default
I'm accessing the config like this:
Copy code
fun Application.configureRouting() {
    println(environment.config.propertyOrNull("media.dir"))
}
it's always null though
is the configuration not parsed yet at that point?
a
Can you show the code of the
main
function?
b
Copy code
fun main() {
    embeddedServer(Netty, port = 8080, host = "127.0.0.1", module = Application::module)
        .start(wait = true)
}
basically the generated main function from intellij
hah got it
intellij generates an application.conf file in resources that isn't read using the default main function
a
The
application.conf
isn't loaded with that configuration. You need to use EngineMain.
Yes
b
thank you, that cleared things up 🙂