This discussion is archived
3 Replies Latest reply: Oct 10, 2012 8:26 AM by TPD-Opitz-Consulting-com RSS

Find the installation Path of the current running VM on Windows

965397 Newbie
Currently Being Moderated
Hello,
I have a java class started by webstart.

In this class I would like to find the absolute path of the current running vm? This is important to me because I need to start an exe file (using ProcessBuilder) and hand it the path of the java VM,

For example I could try something like this:

private static File findJDK() throws Exception {
String s = System.getProperty("java.home");

File myJRE = new File(s);
if (new File(myJRE, "bin/javac.exe").isFile()) {
return myJRE;
}
File parent = myJRE.getParentFile();
if (new File(parent, "bin/javac.exe").isFile()) {
return parent;
}
for (String pathel : System.getenv("PATH").split(File.pathSeparator)) {
File bindir = new File(pathel);
if (new File(bindir, "javac.exe").isFile()) {
return bindir.getParentFile();
}
}
return myJRE;
}

But I would like the above code to be more fool proof!
For example the "java.home" could be wrongly set.


Since java is allready running I would have hopped that I could query the Runtime. But there seems to be no method providing the running java VM path?
I also tried looking at the jnlp services API but no luck.

I would be also interested find the lastest java VM on the client Windows machine....


Many greetings
john

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points