I have some Java code that launches a new Java process, effectively using the default system JRE (in my case JDK 8). Instead I need it to run with the version that is running the original process (e.g. JDK 9).
How can I do that? (The solution needs to work on both Java 8 and 9.)
Details
The code currently relies on the default system JRE by simply issuing a java ...
command. An alternative would be to use something akin to System.getProperty("java.home") + "/bin/java"
(but platform independent), but both have the same problem (for me): They launch a Java process with the JVM version known to the system.
UPDATE: That's utterly wrong, System.getProperty("java.home")
indeed does what I want and returns the current JVM's home directory. (Stupid me, I thought I tried that.)
One way to launch with the same Java version, would be to ask the current process for it's executable and reuse that one, but I found no API for that.