I bundle my macOS JVM app with a helper tool - thi...
# compose-desktop
s
I bundle my macOS JVM app with a helper tool - this is placed in
Contents/app/resources
(the default location). Now I want my app to call it using
Runtime.getRuntime().exec()
. My problem is that I don't know the folder in which my app is executed.
System.getProperty("user.dir")
always returns
/
. On Windows I get the actual directory where my app is living. How can I determine the correct path to my helper tool?
1
e
[[NSBundle mainBundle] pathForResource:ofType:]
normally but I don't know how to access that from JVM
s
Me neither. 😕
A hack I see could be to use
DYLD_LIBRARY_PATH
which seems to be set for the skiko lib. But that of course feels wrong.
e
s
Yes, doesn't look like they want us to use it. 🙄 Otherwise this looks like the thing I'm looking for.
Copy code
java.lang.IllegalAccessError: class MainKt (in unnamed module @0x2080a082) cannot access class com.apple.eio.FileManager (in module java.desktop) because module java.desktop does not export com.apple.eio to unnamed module @0x2080a082
e
oh if that's the only issue then
--add-opens java.desktop/com.apple.eio=ALL-UNNAMED
would get around it
p
On Unix (including Linux) systems there is no real ability to determine the location of the executable that started the program (it could even have multiple locations). In many cases it is recorded using a system specific way (procps), but there is no guarantee that this exists (the only thing available is the command it is invoked as (as the 0-th argument). The way this is generally solved is to either have a hardcoded location (eg.
/usr/libexec/<myProg>
| common with open source programs) or to use some configuration file).
s
Maybe is easier to copy the executable(s) in a temp dir and execute it. But that could impact with MacOS security model.
m
If using Conveyor it's in the
app.dir
system property
Otherwise yes you need native code to get it. Or an obj-c bridge
s
Maybe is easier to copy the executable(s) in a temp dir and execute it. But that could impact with MacOS security model.
Yes, it must be part of the App and be signed. Otherwise, it will not be executed.
oh if that's the only issue then
--add-opens java.desktop/com.apple.eio=ALL-UNNAMED
would get around it
How can I configure this?
s
I configured something similar in gradle:
Copy code
modules("java.sql", "java.desktop", "java.naming")
Mine is something like this:
Copy code
compose.desktop {

    application {
        mainClass = "passwordStore.MainKt"
        jvmArgs += listOf("-Dkpassword-store.mode=PROD")

        nativeDistributions {
            targetFormats(TargetFormat.Rpm, TargetFormat.Msi)
            packageName = "kpassword-store"
            modules("java.sql", "java.desktop", "java.naming")
            packageVersion = semver.version.substringBefore('-')
            licenseFile.set(File("LICENSE"))
            vendor = "Mirko Sciachero <m.sciachero@gmail.com>"
            this.description = """
                Program to manage and store credentials, similar to keepass but simpler \
                Implemented in Kotlin and JCompose
            """.trimIndent()



            linux {
                menuGroup = "Password Store"
                rpmLicenseType = "UNLICENSE"
                iconFile.set(File("src/main/resources/icons/lockoverlay.png"))
                this.shortcut = true
            }
            windows {
                upgradeUuid = "89c4e09f-40e5-4542-9396-934cca615a63"
                menuGroup = "Password Store"
                vendor = "Mirko Sciachero"
                console = false
                iconFile.set(File("lockoverlay.ico"))
            }
        }
    }
}
try to add in a
macos
configuration
s
I think "java.desktop" is exported by default. I tried
modules("java.sql", "java.desktop", "com.apple.eio")
, but that's not correct. There must be a way to add additional compiler config strings, which I don't see right now.
s
But your problem is at compile time or at runtime?
s
Compile time.
Symbol is declared in module 'java.desktop' which does not export package 'com.apple.eio'
s
could be that in some way is hidden, in this scenario not sure how to override it. Because the module decide to keep it private
s
I guess @ephemient will know 🙂
s
maybe try to add as jvmArgs
s
Oh, I think, I found it. Yes, it is.
s
or in the compileKotlin step
so which is the solution 🙂
s
I'm curious: How would it look like in the compile step?
I also found that there is a system property
compose.application.resources.dir
Thank you all for your help. 🙏