diff --git a/common/CHANGES.txt b/common/CHANGES.txt index c667541f05..6f72235a41 100644 --- a/common/CHANGES.txt +++ b/common/CHANGES.txt @@ -215,6 +215,8 @@ Trunk (unreleased changes) HADOOP-7106. Reorganize project SVN layout to "unsplit" the projects. (todd, nigel) + HADOOP-6605. Add JAVA_HOME detection to hadoop-config. (eli) + OPTIMIZATIONS HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole diff --git a/common/bin/hadoop-config.sh b/common/bin/hadoop-config.sh index 6389ac5681..7a55903993 100644 --- a/common/bin/hadoop-config.sh +++ b/common/bin/hadoop-config.sh @@ -107,18 +107,26 @@ fi # we use in Hadoop. Tune the variable down to prevent vmem explosion. export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-4} -# some Java parameters -if [ "$JAVA_HOME" != "" ]; then - #echo "run java in $JAVA_HOME" - JAVA_HOME=$JAVA_HOME -fi - -if [ "$JAVA_HOME" = "" ]; then - echo "Error: JAVA_HOME is not set." - exit 1 +# Attempt to set JAVA_HOME if it is not set +if [[ -z $JAVA_HOME ]]; then + # On OSX use java_home (or /Library for older versions) + if [ "Darwin" == "$(uname -s)" ]; then + if [ -x /usr/libexec/java_home ]; then + export JAVA_HOME=($(/usr/libexec/java_home)) + else + export JAVA_HOME=(/Library/Java/Home) + fi + fi + + # Bail if we did not detect it + if [[ -z $JAVA_HOME ]]; then + echo "Error: JAVA_HOME is not set and could not be found." 1>&2 + exit 1 + fi fi JAVA=$JAVA_HOME/bin/java +# some Java parameters JAVA_HEAP_MAX=-Xmx1000m # check envvars which might override default args