https://kotlinlang.org logo
Title
s

Stefan Oltmann

10/15/2021, 12:10 PM
How can I pass command line arguments to my EXE von Windows?
MyApp.exe hello
results in
Failed to launch JVM
Background: My use case is that I registered a custom URI scheme "myapp://" on Windows and I want to pass all that into my EXE to get back the OAuth response. Is it really possible that the EXE produced by jpackage is not capable of passing cmd line arguments? 🤔
m

Michael Paus

10/15/2021, 5:42 PM
Did you check whether your Kotlin main function actually has a parameter array? And what kind of EXE did you create? An installer EXE or an APP-IMAGE exe? I can only guess because I don’t use Windows but jpackage should not have a problem with that.
s

Stefan Oltmann

10/18/2021, 8:28 AM
Yes, my Kotlin main function takes params and I'm speaking of the APP-IMAGE exe... This wrapper thingy that calls my JAR files with the bundled JRE. Since it has no usage and giving ANY parameter results in failure I begin to doubt that this functionality is there. I expected that it just would pass all parameters to my main-class, but that does not happen.
m

Michael Paus

10/18/2021, 10:04 AM
I just gave this a try with a JavaFX application on macOS which was also packaged with jpackage. I started it from the command line and it printed all arguments which I gave it. (I put the print statement into the main method.) So, at least on the Mac jpackage does forward the arguments to the main method. (I can’t do that on Windows because I don’t use Windows.)
Just verified that it also works the same with Compose-Desktop on Mac. So this must be a Windows issue if there is not a completely different reason.
s

Stefan Oltmann

10/18/2021, 12:46 PM
Thanks for that info. On Mac I don't need it in my case because this just works:
Desktop.getDesktop().setOpenURIHandler { event ->
     // do something
}
I kinda solved it on Windows now with build a second native EXE that just writes any parameter to temp file and my main program watches this using Java NIO FileWatcher.
Thanks for your investigation. Now I know that it should work in general and is messed up on Windows.