Skip to content

Commit

Permalink
Look for javac instead of java
Browse files Browse the repository at this point in the history
There are some situations where using `bin/java` as a heuristic
to find JAVA_HOME within a JDK package can result in mistakenly
finding a JRE root instead. Looking for `bin/javac` fixes this
since JREs do not have `javac`.

This should fix palantir#97
  • Loading branch information
arlaneenalra authored and Jonah Beckford committed Oct 6, 2023
1 parent 9ffb0aa commit 46bdcfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Path findJavaHome(Path temporaryJdkPath) {
return files.filter(file -> Files.isRegularFile(file)
// macos JDKs have a `bin/java` symlink to `Contents/Home/bin/java`
&& !Files.isSymbolicLink(file)
&& file.endsWith(Paths.get("bin", SystemTools.java())))
&& file.endsWith(Paths.get("bin", SystemTools.javac())))
.findFirst()
// JAVA_HOME/bin/java
.orElseThrow(() -> new RuntimeException("Failed to find java home in " + temporaryJdkPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ static String java() {
return "java";
}

static String javac() {
if (Os.current() == Os.WINDOWS) {
return "javac.exe";
}
return "javac";
}

static String keytool() {
if (Os.current() == Os.WINDOWS) {
return "keytool.exe";
Expand Down

0 comments on commit 46bdcfb

Please sign in to comment.