Bug 546216 - Eclipse does not recognize jre located along with eclipse
executable

Change-Id: I51c121c7b32042a1c6b7852c6d84a12f206c13ab
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
index 6e92ad5..c27de61 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
@@ -1873,7 +1873,7 @@
 	 * <li>The default VM</li>
 	 * </ul>
 	 * This state will be read again upon first access to VM configuration information.
-	 * 
+	 *
 	 * @throws CoreException
 	 *             if trying to save the current state of VMs encounters a problem
 	 */
@@ -2232,6 +2232,15 @@
 				// Create a stand-in for the detected VM and add it to the result collector
 				String vmID = String.valueOf(unique);
 				VMStandin detectedVMStandin = new VMStandin(vmType, vmID);
+
+				// Java 9 and above needs the vmInstall location till jre
+				File pluginDir = new File(detectedLocation, "plugins"); //$NON-NLS-1$
+				File featuresDir = new File(detectedLocation, "features"); //$NON-NLS-1$
+				if (pluginDir.exists() && featuresDir.exists()) {
+					if (isJREVersionAbove8(vmType, detectedLocation)) {
+						detectedLocation = new File(detectedLocation, "jre"); //$NON-NLS-1$
+					}
+				}
 				detectedVMStandin.setInstallLocation(detectedLocation);
 				detectedVMStandin.setName(generateDetectedVMName(detectedVMStandin));
 				if (vmType instanceof AbstractVMInstallType) {
@@ -2249,6 +2258,23 @@
 		return null;
 	}
 
+	private static boolean isJREVersionAbove8(IVMInstallType vmType, File installLocation) {
+		LibraryLocation[] locations = vmType.getDefaultLibraryLocations(installLocation);
+		boolean exist = true;
+		for (int i = 0; i < locations.length; i++) {
+			exist = exist && new File(locations[i].getSystemLibraryPath().toOSString()).exists();
+		}
+		if (exist) {
+			return false;
+		}
+		exist = true;
+		LibraryLocation[] newLocations = vmType.getDefaultLibraryLocations(new File(installLocation, "jre")); //$NON-NLS-1$
+		for (int i = 0; i < newLocations.length; i++) {
+			exist = exist && new File(newLocations[i].getSystemLibraryPath().toOSString()).exists();
+		}
+		return exist;
+	}
+
 	/**
 	 * Returns whether the specified option is the same in the given
 	 * map and preference store.