Skip to content

Commit 7855f58

Browse files
committed
Have jar command respect JAVA_HOME + check for jar errors both cases
Both cases being building the uber assembly jar and building the deps assembly jar.
1 parent c16bbfd commit 7855f58

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

bin/compute-classpath.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ 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"
35+
if [ -n "$JAVA_HOME" ]; then
36+
JAR_CMD="$JAVA_HOME/bin/jar"
3737
else
3838
JAR_CMD="jar"
3939
fi
@@ -52,28 +52,30 @@ if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
5252
CLASSPATH="$CLASSPATH:$FWDIR/sql/hive/target/scala-$SCALA_VERSION/classes"
5353
CLASSPATH="$CLASSPATH:$FWDIR/yarn/stable/target/scala-$SCALA_VERSION/classes"
5454

55-
DEPS_ASSEMBLY_JAR=$(ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar 2>/dev/null)
56-
CLASSPATH="$CLASSPATH:$DEPS_ASSEMBLY_JAR"
55+
ASSEMBLY_JAR=$(ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar 2>/dev/null)
5756
else
5857
# Else use spark-assembly jar from either RELEASE or assembly directory
5958
if [ -f "$FWDIR/RELEASE" ]; then
6059
ASSEMBLY_JAR=$(ls "$FWDIR"/lib/spark-assembly*hadoop*.jar 2>/dev/null)
6160
else
6261
ASSEMBLY_JAR=$(ls "$ASSEMBLY_DIR"/spark-assembly*hadoop*.jar 2>/dev/null)
6362
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
72-
CLASSPATH="$CLASSPATH:$ASSEMBLY_JAR"
7363
fi
7464

65+
# Verify that versions of java used to build the jars and run Spark are compatible
66+
jar_error_check=$("$JAR_CMD" -tf "$ASSEMBLY_JAR" scala/AnyVal 2>&1)
67+
if [[ "$jar_error_check" =~ "invalid CEN header" ]]; then
68+
echo "Loading Spark jar with '$JAR_CMD' failed. "
69+
echo "This is likely because Spark was compiled with Java 7 and run "
70+
echo "with Java 6. (see SPARK-1703). Please use Java 7 to run Spark "
71+
echo "or build Spark with Java 6."
72+
exit 1
73+
fi
74+
75+
CLASSPATH="$CLASSPATH:$ASSEMBLY_JAR"
76+
7577
# When Hive support is needed, Datanucleus jars must be included on the classpath.
76-
# Datanucleus jars do not work if only included in the uber jar as plugin.xml metadata is lost.
78+
# Datanucleus jars do not work if only included in the uber jar as plugin.xml metadata is lost.
7779
# Both sbt and maven will populate "lib_managed/jars/" with the datanucleus jars when Spark is
7880
# built with Hive, so first check if the datanucleus jars exist, and then ensure the current Spark
7981
# assembly is built for Hive, before actually populating the CLASSPATH with the jars.
@@ -88,11 +90,10 @@ datanucleus_jars=$(find "$datanucleus_dir" 2>/dev/null | grep "datanucleus-.*\\.
8890
datanucleus_jars=$(echo "$datanucleus_jars" | tr "\n" : | sed s/:$//g)
8991

9092
if [ -n "$datanucleus_jars" ]; then
91-
an_assembly_jar=${ASSEMBLY_JAR:-$DEPS_ASSEMBLY_JAR}
92-
hive_files=$(jar tvf "$an_assembly_jar" org/apache/hadoop/hive/ql/exec 2>/dev/null)
93+
hive_files=$("$JAR_CMD" -tf "$ASSEMBLY_JAR" org/apache/hadoop/hive/ql/exec 2>/dev/null)
9394
if [ -n "$hive_files" ]; then
9495
echo "Spark assembly has been built with Hive, including Datanucleus jars on classpath" 1>&2
95-
CLASSPATH=$CLASSPATH:$datanucleus_jars
96+
CLASSPATH="$CLASSPATH:$datanucleus_jars"
9697
fi
9798
fi
9899

make-distribution.sh

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

54-
if [ -z "${JAVA_HOME}" ]; then
54+
if [ -z "$JAVA_HOME" ]; then
5555
echo "Error: JAVA_HOME is not set, cannot proceed."
5656
exit -1
5757
fi
5858

59-
JAVA_CMD=$JAVA_HOME/bin/java
60-
JAVA_VERSION=$($JAVA_CMD -version 2>&1)
59+
JAVA_CMD="$JAVA_HOME"/bin/java
60+
JAVA_VERSION=$("$JAVA_CMD" -version 2>&1)
6161
if ! [[ "$JAVA_VERSION" =~ "1.6" ]]; then
6262
echo "Error: JAVA_HOME must point to a JDK 6 installation (see SPARK-1703)."
6363
echo "Output from 'java -version' was:"

0 commit comments

Comments
 (0)