在 ./gradlew run 中编写多平台应用程序工作正常,但在运行 ./gradlew runDistributable 后,使用 ktor 进行 api 调用时会出现异常
java/rmi/ConnectException
。
模块-
val provideKtorClient = module {
single {
HttpClient {
expectSuccess = true
install(ContentNegotiation) {
json(Json {
prettyPrint = true
ignoreUnknownKeys = true
})
}
install(HttpTimeout) {
requestTimeoutMillis = 2000
}
HttpResponseValidator {
handleResponseExceptionWithRequest { cause, _ ->
when (cause) {
is ClientRequestException -> {
val response: ErrorResponse = cause.response.body()
throw ServerExceptionResponse(response)
}
}
}
}
}
}
}
Progaurd 可能在尝试运行时删除了一些必要的东西
./gradlew packageForCurrentOS
有什么建议吗?出了什么问题!
堆栈跟踪 -
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: java/rmi/ConnectException
at presentation.home.HomeKt$Home$submitStudentActivity$1.invokeSuspend(Home.kt:218)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$2$1.invoke(FlushCoroutineDispatcher.skiko.kt:62)
at androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$2$1.invoke(FlushCoroutineDispatcher.skiko.kt:57)
at androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun(FlushCoroutineDispatcher.skiko.kt:91)
at androidx.compose.ui.platform.FlushCoroutineDispatcher.access$performRun(FlushCoroutineDispatcher.skiko.kt:37)
at androidx.compose.ui.platform.FlushCoroutineDispatcher$dispatch$2.invokeSuspend(FlushCoroutineDispatcher.skiko.kt:57)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.awt.ComposeBridge$coroutineExceptionHandler$1@18b92998, androidx.compose.runtime.BroadcastFrameClock@15b74cff, StandaloneCoroutine{Cancelling}@36418987, FlushCoroutineDispatcher@19e2cbec]
Caused by: java.lang.ClassNotFoundException: java.rmi.ConnectException
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)
... 23 more
当我尝试使用 ktor 调用 api 时的屏幕截图 -
在调试/开发模式下一切正常。
我正在导入
java.rmi.ConnectException
通过导入解决了问题
java.net.ConnectException
但仍有疑问!
但是为什么
java.rmi.ConnectException
在开发模式下工作而不是在发布模式下工作?