I have Java code that starts a new Java process, effectively using the default JRE system (in my case, JDK 8). Instead, I need it to start with a version that starts the original process (e.g. JDK 9).
How can i do this? (The solution should work on both Java 8 and 9.)
More details
Currently, the code relies on the default JRE system by simply issuing the java ... command. An alternative would be to use something similar to System.getProperty("java.home") + "/bin/java" (but not platform dependent), but both have the same problem (for me): they start the Java process with a version of the JVM known to the system.
UPDATE This is completely wrong, System.getProperty("java.home") really does what I want and returns the current JVM home directory. (Stupid me, I thought I tried this.)
One way to start with the same Java version is to request the current process for its executable and reuse, but I did not find an API for it.
source share