View all available java versions on the machine


I'm writing an eclipse plug-in and I need to display all versions of Java installed on users machine. I know about this code:

String javaVersion = System.getProperty("java.version");

but it only returns currently selected Java version. How would I get them all?

This is much more complicated then you think.

Of course, when you run some java class; that already runs inside a single JVM. And that JVM installation doesn't have any idea if/where other JVMs might exist on your system.

Therefore it depends on your operating system where other JVMs might be located.

On a Linux system, you could go for

find / -name "java" -type f 2>/dev/null

On my system, that creates output like:


That is the whole point: a user can place JVM binaries all over his file system. And he could be starting a JVM within all those different directories.

So the real answer here: step back; and look at the requirement behind your question. Why do you think you need to know about this? And from there: how can you get rid of the requirement?