@@ -32,8 +32,8 @@ 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" 
35+ if  [ -n  " $JAVA_HOME " ;  then 
36+   JAR_CMD=" $JAVA_HOME /bin/jar" 
3737else 
3838  JAR_CMD=" jar" 
3939fi 
@@ -52,40 +52,48 @@ 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 " * hadoop* -deps.jar` 
56-   CLASSPATH=" $CLASSPATH :$DEPS_ASSEMBLY_JAR " 
55+   ASSEMBLY_JAR=$( ls " $ASSEMBLY_DIR " * hadoop* -deps.jar 2> /dev/null) 
5756else 
5857  #  Else use spark-assembly jar from either RELEASE or assembly directory
5958  if  [ -f  " $FWDIR /RELEASE" ;  then 
60-     ASSEMBLY_JAR=` ls " $FWDIR " * hadoop* .jar` 
59+     ASSEMBLY_JAR=$( ls " $FWDIR " * hadoop* .jar  2> /dev/null ) 
6160  else 
62-     ASSEMBLY_JAR=` ls " $ASSEMBLY_DIR " * hadoop* .jar` 
61+     ASSEMBLY_JAR=$( ls " $ASSEMBLY_DIR " * 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 " 
7363fi 
7464
65+ #  Verify that versions of java used to build the jars and run Spark are compatible
66+ jar_error_check=$( " $JAR_CMD " " $ASSEMBLY_JAR " 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.
8082#  Note that this check order is faster (by up to half a second) in the case where Hive is not used.
81- num_datanucleus_jars=$( ls " $FWDIR " 2> /dev/null |  grep " datanucleus-.*\\ .jar" |  wc -l) 
82- if  [ $num_datanucleus_jars  -gt  0 ];  then 
83-   AN_ASSEMBLY_JAR=${ASSEMBLY_JAR:- $DEPS_ASSEMBLY_JAR } 
84-   num_hive_files=$( jar tvf " $AN_ASSEMBLY_JAR " 2> /dev/null |  wc -l) 
85-   if  [ $num_hive_files  -gt  0 ];  then 
83+ if  [ -f  " $FWDIR /RELEASE" ;  then 
84+   datanucleus_dir=" $FWDIR " 
85+ else 
86+   datanucleus_dir=" $FWDIR " 
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 " " $ASSEMBLY_JAR " 2> /dev/null) 
94+   if  [ -n  " $hive_files " ;  then 
8695    echo  " Spark assembly has been built with Hive, including Datanucleus jars on classpath" 1>&2 
87-     DATANUCLEUSJARS=$( echo " $FWDIR /lib_managed/jars" * .jar |  tr "  " ) 
88-     CLASSPATH=$CLASSPATH :$DATANUCLEUSJARS 
96+     CLASSPATH=" $CLASSPATH :$datanucleus_jars " 
8997  fi 
9098fi 
9199
105113#  Add hadoop conf dir if given -- otherwise FileSystem.*, etc fail !
106114#  Note, this assumes that there is either a HADOOP_CONF_DIR or YARN_CONF_DIR which hosts
107115#  the configurtion files.
108- if  [ " x "   !=   " x $HADOOP_CONF_DIR " ;  then 
116+ if  [ -n   " $HADOOP_CONF_DIR " ;  then 
109117  CLASSPATH=" $CLASSPATH :$HADOOP_CONF_DIR " 
110118fi 
111- if  [ " x "   !=   " x $YARN_CONF_DIR " ;  then 
119+ if  [ -n   " $YARN_CONF_DIR " ;  then 
112120  CLASSPATH=" $CLASSPATH :$YARN_CONF_DIR " 
113121fi 
114122
0 commit comments