I compiled my Java application with (GluonFX which itself uses) GraalVM. How can I get the directory where my application binary resides at runtime? (not the users working directory)
- Before using GraalVMs native-image tool, I used to read
System.getProperty("java.home")and deduced it from there. But this system property does not exist anymore. - I tried to find another system property, but the directory of my application was in none.
- I tried to read environment variables and found
System.getenv("_"), but as "_ contains the last program run", this does not feel stable. - I tried to resolve
Paths.get(".").toAbsolutePath()but this only returned the current working directory.
My end goal is to package this small application binary in a bigger application and this small application should call other applications which will get packaged next to it.
You can get the running path from java code like below
Please change the Main class to the class you use in your code.
There is another way too but that requires nativeimage dependency.
then call it like below
example output
working example
References