Improve error handling in failure to find JRE in JAVA_HOME

This commit is contained in:
Kris De Volder
2018-02-09 18:01:26 -08:00
parent 28d598b93d
commit 12b788c1f3
2 changed files with 18 additions and 9 deletions

View File

@@ -103,6 +103,7 @@ export function findJdk(javaHome?: string) : Promise<JVM | null> {
* search logic and uses that javaHome as is, not looking anywhere else.
*/
function findJavaExe(javaHome?: string) : string | null {
//Try java home first
if (!javaHome) {
javaHome = process.env["JAVA_HOME"];
}
@@ -112,14 +113,17 @@ function findJavaExe(javaHome?: string) : string | null {
}
let binName = correctBinname("java");
if (javaHome) {
return Path.resolve(javaHome, "bin", binName);
} else {
for (var searchPath of process.env['PATH'].split(Path.delimiter)) {
let javaExe = Path.resolve(searchPath, binName);
if (FS.existsSync(javaExe)) {
//Resolve symlinks
return FS.realpathSync(javaExe);
}
let javaExe = Path.resolve(javaHome, "bin", binName);
if (FS.existsSync(javaExe)) {
return javaExe;
}
}
for (var searchPath of process.env['PATH'].split(Path.delimiter)) {
let javaExe = Path.resolve(searchPath, binName);
if (FS.existsSync(javaExe)) {
//Resolve symlinks
return FS.realpathSync(javaExe);
}
}
return null;

View File

@@ -76,7 +76,12 @@ export function activate(options: ActivatorOptions, context: VSCode.ExtensionCon
let findJRE = options.preferJdk ? findJdk : findJvm;
return findJRE().then(jvm => {
return findJRE()
.catch(error => {
VSCode.window.showErrorMessage("Error trying to find JVM: "+error);
return Promise.reject(error);
})
.then(jvm => {
if (!jvm) {
VSCode.window.showErrorMessage("Couldn't locate java in $JAVA_HOME or $PATH");
return;