I need to use ProcessBuilder to invoke java -jar another-program.jar in a Java program. When Java is not in $PATH I will need to find the location of current running Java process, otherwise ProcessBuilder will throw IOException.
One working solution is this:
String javaPath = System.getProperty("java.home") + "/bin/java";
But when I run the Java program with JDK, it will return the Java binary inside the JRE folder instead.
How can I retrieve the correct Java path?
I don't want to rely on JAVA_HOME or /proc/self/exe, hopefully there's a pure Java solution.