JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.89k stars 1.15k forks source link

Failed to instantiate SLF4J LoggerFactory when including ktor in package #1977

Open Klurige opened 2 years ago

Klurige commented 2 years ago

My project runs a Jetpack Compose Desktop client and a ktor server. The error stems from ktor, but given that the error only occurs when executing the installed deb package suggests that there is something wrong in the debs package generation. Running from within IntelliJ works fine. Executing the installed package from command line spits out this error: Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: javax/naming/NamingException at ch.qos.logback.classic.joran.JoranConfigurator.addInstanceRules(JoranConfigurator.java:48) at ch.qos.logback.core.joran.GenericConfigurator.buildInterpreter(GenericConfigurator.java:134) at ch.qos.logback.core.joran.JoranConfiguratorBase.buildInterpreter(JoranConfiguratorBase.java:95) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:162) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110) at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53) at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84) at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:55) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362) at io.ktor.server.engine.ApplicationEngineEnvironmentBuilder.(ApplicationEngineEnvironmentJvm.kt:36) at io.ktor.server.engine.ApplicationEngineEnvironmentKt.applicationEngineEnvironment(ApplicationEngineEnvironment.kt:48) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:90) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:63) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer(EmbeddedServer.kt:38) at io.ktor.server.engine.EmbeddedServerKt.embeddedServer$default(EmbeddedServer.kt:30) at MainKt$main$1$2.invokeSuspend(Main.kt:49) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665) Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ... 28 more

I am running on Linux and generate the package with "gradlew package". But unsurprisingly the same error occurs if generating the package from within idea.

Here is the project in question, for your perusal: https://github.com/Klurige/ktor_compose

AlexeyTsvetkov commented 2 years ago

Could you try adding java.naming JDK module?

compose.desktop {
    application {
        nativeDistributions {
            modules("java.naming")
            // alternatively: includeAllModules = true
        }
    }
}

https://github.com/JetBrains/compose-jb/tree/master/tutorials/Native_distributions_and_local_execution#configuring-included-jdk-modules

Klurige commented 2 years ago

Just adding "java.naming" got me a bit further. Now it stopped at "java.lang.NoClassDefFoundError: java/lang/management/ManagementFactory"

But "includeAllModules = true" took me all the way. I finally limited the modules to "java.instrument", "java.management", "java.naming", "java.sql", "jdk.unsupported".

I discovered a documentation error on the page you directed me to: task "suggestModules" is now called "suggestRuntimeModules".

Thank you for your help!

okushnikov commented 2 weeks ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.