Hi, I have a fat jar file that I've created with k...
# ktor
m
Hi, I have a fat jar file that I've created with kvision that contains my ktor 3.0 application. When I run it, it's starting the right class, but the application.conf file isn't being read, so it fails to get any configuration. My starting function (in
/bw/App.kt
) is:
Copy code
fun main() = runBlocking {
    logger.info("Starting Bouncy World Service at ${Date()}")
    val env = applicationEnvironment {
        config = ApplicationConfig("application.conf")
    }
    val worldConfig = WorldConfig(env.config)
    val world = WorldFactory.create(worldConfig)
I can see and have validated the application.conf file in the root of the jar folder. When starting up, I see the logger information, but the instantiation of worldConfig fails, because there's nothing in env.config (I print out the keys in the init section of WorldConfig, and it's showing an empty list). My gradle build has the main class set with:
Copy code
jvm {
        @OptIn(ExperimentalKotlinGradlePluginApi::class)
        mainRun {
            mainClass.set("bw.AppKt")
        }
This works fine outside a jar file invocation (i.e. clicking the start button in IntelliJ for the application) i.e. via:
Copy code
jvmRun -DmainClass=bw.AppKt --quiet
Can anyone suggest why the config isn't being read when running the application via
Copy code
java -jar path/to/my.jar
I tried adding
-conf
param, but as I'm not using the EngineMain to create the server, it's not doing anything.
After debugging this for a while, it appears the
io.ktor.server.config.HoconConfigLoader
is not available when running by the jar, but only when run from the IDE. Does anyone know how to get that to load in the jar too?
I can see
io/ktor/server/config/HoconConfigLoader.class
exists in the fat jar. Now just need to know why it's not registering
The jar's
io.ktor.server.config.ConfigLoader
file only contains:
Copy code
io.ktor.server.config.yaml.YamlConfigLoader
and not
Copy code
io.ktor.server.config.HoconConfigLoader
I was loading ktor-server-config-yaml-jvm as a dependency, if I remove it, then the HoconConfigLoader is included. Does anyone know how to include both?
a
The
HoconConfigLoader
class is part of the
ktor-server-core
package, so it should be loaded anyway. Do you plan to use the YAML or the HOCON configuration?
m
I'm actually just using HOCON for the main config at the moment, but was trying out YAML too, noticed that in the IDE via "jvmRun" both work, but when using a JAR, the HoconConfigLoader isn't loaded, only the YAML one is. I've also raised this in the #CL4C1SLKC channel.
a
As a workaround, you can try to use the
HoconConfigLoader
class directly to load the config.
m
Thanks. I've removed the YAML, it's a small project, and I'm not using that. I'm unsure though why only one of them is getting registered. Feels like it's somewhere in the building of the jar (using shadowJar from kvision's gradle plugin) or if the ktor fatJar task would instead get it correct (but then wouldn't build the Web App for kvision)