Improve error handling in failure to find JRE in JAVA_HOME
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user