@@ -32,6 +32,12 @@ CLASSPATH="$SPARK_CLASSPATH:$SPARK_SUBMIT_CLASSPATH:$FWDIR/conf"
3232
3333ASSEMBLY_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
3642if [ -f " $ASSEMBLY_DIR " /spark-assembly* hadoop* -deps.jar ]; then
3743 CLASSPATH=" $CLASSPATH :$FWDIR /core/target/scala-$SCALA_VERSION /classes"
@@ -44,33 +50,50 @@ if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
4450 CLASSPATH=" $CLASSPATH :$FWDIR /sql/catalyst/target/scala-$SCALA_VERSION /classes"
4551 CLASSPATH=" $CLASSPATH :$FWDIR /sql/core/target/scala-$SCALA_VERSION /classes"
4652 CLASSPATH=" $CLASSPATH :$FWDIR /sql/hive/target/scala-$SCALA_VERSION /classes"
53+ CLASSPATH=" $CLASSPATH :$FWDIR /yarn/stable/target/scala-$SCALA_VERSION /classes"
4754
48- DEPS_ASSEMBLY_JAR=` ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* -deps.jar`
49- CLASSPATH=" $CLASSPATH :$DEPS_ASSEMBLY_JAR "
55+ ASSEMBLY_JAR=$( ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* -deps.jar 2> /dev/null)
5056else
5157 # Else use spark-assembly jar from either RELEASE or assembly directory
5258 if [ -f " $FWDIR /RELEASE" ]; then
53- ASSEMBLY_JAR=` ls " $FWDIR " /lib/spark-assembly* hadoop* .jar`
59+ ASSEMBLY_JAR=$( ls " $FWDIR " /lib/spark-assembly* hadoop* .jar 2> /dev/null )
5460 else
55- ASSEMBLY_JAR=` ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* .jar`
61+ ASSEMBLY_JAR=$( ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* .jar 2> /dev/null )
5662 fi
57- CLASSPATH=" $CLASSPATH :$ASSEMBLY_JAR "
5863fi
5964
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 " nonexistent/class/path 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+
6077# When Hive support is needed, Datanucleus jars must be included on the classpath.
61- # 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.
6279# Both sbt and maven will populate "lib_managed/jars/" with the datanucleus jars when Spark is
6380# built with Hive, so first check if the datanucleus jars exist, and then ensure the current Spark
6481# assembly is built for Hive, before actually populating the CLASSPATH with the jars.
6582# Note that this check order is faster (by up to half a second) in the case where Hive is not used.
66- num_datanucleus_jars=$( ls " $FWDIR " /lib_managed/jars/ 2> /dev/null | grep " datanucleus-.*\\ .jar" | wc -l)
67- if [ $num_datanucleus_jars -gt 0 ]; then
68- AN_ASSEMBLY_JAR=${ASSEMBLY_JAR:- $DEPS_ASSEMBLY_JAR }
69- num_hive_files=$( jar tvf " $AN_ASSEMBLY_JAR " org/apache/hadoop/hive/ql/exec 2> /dev/null | wc -l)
70- if [ $num_hive_files -gt 0 ]; then
83+ if [ -f " $FWDIR /RELEASE" ]; then
84+ datanucleus_dir=" $FWDIR " /lib
85+ else
86+ datanucleus_dir=" $FWDIR " /lib_managed/jars
87+ fi
88+
89+ datanucleus_jars=$( find " $datanucleus_dir " 2> /dev/null | grep " datanucleus-.*\\ .jar" )
90+ datanucleus_jars=$( echo " $datanucleus_jars " | tr " \n" : | sed s/:$//g)
91+
92+ if [ -n " $datanucleus_jars " ]; then
93+ hive_files=$( " $JAR_CMD " -tf " $ASSEMBLY_JAR " org/apache/hadoop/hive/ql/exec 2> /dev/null)
94+ if [ -n " $hive_files " ]; then
7195 echo " Spark assembly has been built with Hive, including Datanucleus jars on classpath" 1>&2
72- DATANUCLEUSJARS=$( echo " $FWDIR /lib_managed/jars" /datanucleus-* .jar | tr " " :)
73- CLASSPATH=$CLASSPATH :$DATANUCLEUSJARS
96+ CLASSPATH=" $CLASSPATH :$datanucleus_jars "
7497 fi
7598fi
7699
90113# Add hadoop conf dir if given -- otherwise FileSystem.*, etc fail !
91114# Note, this assumes that there is either a HADOOP_CONF_DIR or YARN_CONF_DIR which hosts
92115# the configurtion files.
93- if [ " x " != " x $HADOOP_CONF_DIR " ]; then
116+ if [ -n " $HADOOP_CONF_DIR " ]; then
94117 CLASSPATH=" $CLASSPATH :$HADOOP_CONF_DIR "
95118fi
96- if [ " x " != " x $YARN_CONF_DIR " ]; then
119+ if [ -n " $YARN_CONF_DIR " ]; then
97120 CLASSPATH=" $CLASSPATH :$YARN_CONF_DIR "
98121fi
99122
0 commit comments