Hi all, I have a multiplatform project (targeting ...
# compose-desktop
f
Hi all, I have a multiplatform project (targeting mainly desktop) and I would like to start an external process (I have an
.exe
which I would like to run when a
Button
is clicked). I figured that I would put that executable in the
composeApp/commonMain/composeResources
directory, but unless I put it inside
files/.../that.exe
, it fails to compile. What's more, when it finally compiled, I don't know if there is a way of safely retrieving it.
composeapp.generated.resources.[...]
does not list that executable. A path to it would be sufficient, I believe. Is there a recommended way of achieving this behavior? Maybe I should be using
object {}.javaClass.classLoader.getResourceAsStream(...)
?
I realized that you can just add a plain, old
resources
directory. But I am enocuntering an interesting issue. My path to that dir is:
<project>\composeApp\src\commonMain\resources\executables\some.exe
. I verified that is it being correctly copied to the build directory, but apparently I get an exception, saying that there is no such file in the resulting `.jar`:
Copy code
Cannot run program 'file:/<project>/composeApp/build/libs/composeApp-desktop.jar!/executables/some.exe': 
CreateProcess error=2, The system cannot find the file specified
The thing is, as I mentioned already, inside the
.jar
there is an
executables
directory with
some.exe
, which means that the project passes it correctly. The only weird thing that caught my attention is that the error mentions
composeApp-desktop.jar!
- that is, with a
!
at the end. Is this normal?
e
that's a "path" to a resource inside a JAR, yes
only Java understands that; for any external processes, you'll need to extract the resource out of the JAR to the real filesystem to make it usable
☝️ 1
f
Managed to solve the issue, but extracting the executable to some local file was only a half of a solution, because for some reason I could not simply copy contents when using
Res.getUri()
. I had to move to plain-old
resources
and use
object {}.javaClass.classLoader.getResourceAsStream(...)
. But it works correctly now
:>