I have a Java application that runs on a developer's machine that has several JVMs installed. This application invokes child Java applications, and (depending on the child application), needs to select an appropriate JVM from all the available JVMs.
The JVM of the child application will not necessarily be the JVM in use by the parent application. For example, the user may have launched the parent application using OpenJDK 1.7.0, but wants to launch a legacy tool as a child process, and that tool requires Sun APIs and hence must be a Sun JDK.
Is there a library that will do a somewhat reasonable job of looking for JVMs on my local machine and provide some API for querying information them, so that when I run my child process, I can pick a reasonable JVM?
What I hope to be able to do is something like:
public Jvm chooseAvailableJvmForDevTool() {
for (Jvm jvm : SomeLibrary.pollJvms()) {
if (jvm.getVersion().getMinor() == 6 && jvm.isHotspot() && jvm.isJDK()) {
return jvm;
}
}
throw new UnsupportedOperationException("This tool requires a Sun Hotspot 1.6 JDK");
}
I have no expectation that such a library would find all of the JVMs, but it would be nice if it could try to find some of them in the obvious places. For example, on a Windows machine, I would hope that it would at least look in C:\Program Files\Java, and on a Linux machine, it would look in /usr/lib/jvm. If I can give the library some likely places where developers at my company like to install their JDKs, all the better. (For example, some Windows developers defensively install Java someplace other than "C:\Program Files\Java" just in case they use a tool that doesn't properly escape the space in "Program Files".)
This question is almost a duplicate of this two year old question... How to programatically get all Java JVM installed (Not default one) using Java?
...but I'm (re)asking in the hopes that in the interim two years, someone may have whipped up an open-source library to do this so we can all benefit from improvements. Anyone know of such a project? (Or can provide a convincing argument why such a library would be a Very Bad Idea?)