Skip to content

Commit

Permalink
fix: Ensure JAVA_HOME path comes first in the PATH environment
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed May 9, 2021
1 parent 6bd740d commit 3310dc7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bin/templates/cordova/lib/env/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ const java = {
const javacPath = utils.forgivingWhichSync('javac');
const hasJavaHome = !!environment.JAVA_HOME;
if (hasJavaHome) {
// Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh).
if (!javacPath) {
environment.PATH += path.delimiter + path.join(environment.JAVA_HOME, 'bin');
}
// Ensure that the JAVA_HOME bin path is before anything else
// to cover cases where different Java versions is in the PATH
environment.PATH = path.join(environment.JAVA_HOME, 'bin') + path.delimiter + environment.PATH;
} else {
if (javacPath) {
// OS X has a command for finding JAVA_HOME.
Expand All @@ -98,7 +97,8 @@ const java = {
} else {
// See if we can derive it from javac's location.
var maybeJavaHome = path.dirname(path.dirname(javacPath));
if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) {
console.log('MAYBE JAVA HOME', maybeJavaHome);
if (fs.existsSync(path.join(maybeJavaHome, 'lib'))) {
environment.JAVA_HOME = maybeJavaHome;
} else {
throw new CordovaError(default_java_error_msg);
Expand Down

0 comments on commit 3310dc7

Please sign in to comment.