Closed OleksiiHromovych closed 4 weeks ago
Found a "dirty fix" for this situation:
application {
Thread.currentThread().contextClassLoader = this.javaClass.classLoader
Window(...
Explanation
In PlatformResourceReader
, ClassLoader
is obtained as follows return Thread.currentThread().contextClassLoader ?: this.javaClass.classLoader!!
But contextClassLoader refers to the launcher loader.
It's interesting that
The general appearance of the launch function after the launcher has the following appearance, for convenience I write which ClassLoader
is used by launcher/app
override fun run(context: LaunchContext) { // app
thread { // app
application { // launcher
Window(...
}
}
}
That is, for some reason, the application call will change the ClassLoader
to another one, although the thread itself will remain the one we defined. Overriding thread(contextClassLoader= ...)
does not help. But if you assign another loader in the application
block, then everything is fine.
I am working with a multi-module project. To create a desktop application, I use a launcher with automatic updates (update4j), and the application itself.
As a result, 2 folders with jar files are formed: The main with launcher & auto-updates - C:\Program Files\MyApp\app With an application that is downloaded from the launcher - C:\Users\Admin\AppData\Local\MyApp\lib
There is a problem with access to resources when starting the application itself due to the use of painterResource.
Maybe the problem is that the jar file used to search for resources is in another directory (the launcher is in the main one).
The search is performed using the
BuiltinClassLoader.findResourceOnClassPath
method, linereturn ucp.findResource(name, false);
compose desktop/run
, the URL is returnedfile:/D:/Projects/IntelliJ/MyApp/composeApp/build/libs/composeApp-jvm.jar!/composeResources/MyApp.composeApp.generated.resources/drawable/compose-multiplatform.xml
Formation and installation through
distributionForCurrent
works. All files are in one directory.Maybe I can additionally specify the path to the files of the main application, or is there another solution to the problem?
Affected platforms
Versions