Skip to content

Commit

Permalink
[SPARK-36856][BUILD] Get correct JAVA_HOME for macOS
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Currently, JAVA_HOME may be set to path "/usr" improperly, now JAVA_HOME is fetched from command "/usr/libexec/java_home" for macOS.

### Why are the changes needed?
Command "./build/mvn xxx" will be stuck on MacOS 11.4, because JAVA_HOME is set to path "/usr" improperly.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
`build/mvn -DskipTests package` passed on `macOS 11.5.2`.

Closes #34111 from copperybean/work.

Authored-by: copperybean <copperybean.zhang@gmail.com>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
  • Loading branch information
copperybean authored and gengliangwang committed Sep 28, 2021
1 parent c3cdb89 commit 56c21e8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion build/mvn
Expand Up @@ -21,7 +21,14 @@ SELF=$(cd $(dirname $0) && pwd)
. "$SELF/util.sh"

if [ -z "${JAVA_HOME}" -a "$(command -v javac)" ]; then
export JAVA_HOME="$(dirname $(dirname $(realpath $(command -v javac))))"
if [ "$(uname -s)" = "Darwin" ]; then
# For some versions of macOS, "/usr/bin/javac" is a real file instead of a symbolic link,
# so the JAVA_HOME may be set to path "/usr" improperly.
# The following command is an appropriate way of setting JAVA_HOME on macOS.
export JAVA_HOME="$(/usr/libexec/java_home)"
else
export JAVA_HOME="$(dirname $(dirname $(realpath $(command -v javac))))"
fi
fi

# Determine the current working directory
Expand Down

0 comments on commit 56c21e8

Please sign in to comment.