Skip to content

Commit 2f091d5

Browse files
committed
SPARK-1703 Warn users if Spark is run on JRE6 but compiled with JDK7.
This add some guards and good warning messages if users hit this issue. /cc @aarondav with whom I discussed parts of the design. Author: Patrick Wendell <[email protected]> Closes #627 from pwendell/jdk6 and squashes the following commits: a38a958 [Patrick Wendell] Code review feedback 94e9f84 [Patrick Wendell] SPARK-1703 Warn users if Spark is run on JRE6 but compiled with JDK7. (cherry picked from commit 0c98a8f) Signed-off-by: Patrick Wendell <[email protected]>
1 parent 40d05a4 commit 2f091d5

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

bin/compute-classpath.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ CLASSPATH="$SPARK_CLASSPATH:$SPARK_SUBMIT_CLASSPATH:$FWDIR/conf"
3232

3333
ASSEMBLY_DIR="$FWDIR/assembly/target/scala-$SCALA_VERSION"
3434

35+
if [ -n "${JAVA_HOME}" ]; then
36+
JAR_CMD="${JAVA_HOME}/bin/jar"
37+
else
38+
JAR_CMD="jar"
39+
fi
40+
3541
# First check if we have a dependencies jar. If so, include binary classes with the deps jar
3642
if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
3743
CLASSPATH="$CLASSPATH:$FWDIR/core/target/scala-$SCALA_VERSION/classes"
@@ -55,6 +61,14 @@ else
5561
else
5662
ASSEMBLY_JAR=`ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*.jar`
5763
fi
64+
jar_error_check=$($JAR_CMD -tf $ASSEMBLY_JAR org/apache/spark/SparkContext 2>&1)
65+
if [[ "$jar_error_check" =~ "invalid CEN header" ]]; then
66+
echo "Loading Spark jar with '$JAR_CMD' failed. "
67+
echo "This is likely because Spark was compiled with Java 7 and run "
68+
echo "with Java 6. (see SPARK-1703). Please use Java 7 to run Spark "
69+
echo "or build Spark with Java 6."
70+
exit 1
71+
fi
5872
CLASSPATH="$CLASSPATH:$ASSEMBLY_JAR"
5973
fi
6074

bin/spark-class

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ if [ -e "$TOOLS_DIR"/target/spark-tools*[0-9Tg].jar ]; then
138138
fi
139139

140140
# Compute classpath using external script
141-
CLASSPATH=`$FWDIR/bin/compute-classpath.sh`
141+
classpath_output=$($FWDIR/bin/compute-classpath.sh)
142+
if [[ "$?" != "0" ]]; then
143+
echo "$classpath_output"
144+
exit 1
145+
else
146+
CLASSPATH=$classpath_output
147+
fi
148+
142149
if [[ "$1" =~ org.apache.spark.tools.* ]]; then
143150
CLASSPATH="$CLASSPATH:$SPARK_TOOLS_JAR"
144151
fi

make-distribution.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ if [ $? != 0 ]; then
5151
exit -1;
5252
fi
5353

54+
if [ -z "${JAVA_HOME}" ]; then
55+
echo "Error: JAVA_HOME is not set, cannot proceed."
56+
exit -1
57+
fi
58+
59+
JAVA_CMD=$JAVA_HOME/bin/java
60+
JAVA_VERSION=$($JAVA_CMD -version 2>&1)
61+
if ! [[ "$JAVA_VERSION" =~ "1.6" ]]; then
62+
echo "Error: JAVA_HOME must point to a JDK 6 installation (see SPARK-1703)."
63+
echo "Output from 'java -version' was:"
64+
echo "$JAVA_VERSION"
65+
exit -1
66+
fi
67+
5468
# Initialize defaults
5569
SPARK_HADOOP_VERSION=1.0.4
5670
SPARK_YARN=false

0 commit comments

Comments
 (0)