Determining location of JVM executable during runtime

You could always just use os.name to check if the user is running Windows or not. That’ll work on OS X, Linux and Windows at

String jvm_location;
if (System.getProperty("os.name").startsWith("Win")) {
    jvm_location = System.getProperties().getProperty("java.home") + File.separator + "bin" + File.separator + "java.exe";
} else {
    jvm_location = System.getProperties().getProperty("java.home") + File.separator + "bin" + File.separator + "java";
}

Leave a Comment