@@ -32,6 +32,12 @@ CLASSPATH="$SPARK_CLASSPATH:$SPARK_SUBMIT_CLASSPATH:$FWDIR/conf"
32
32
33
33
ASSEMBLY_DIR=" $FWDIR /assembly/target/scala-$SCALA_VERSION "
34
34
35
+ if [ -n " $JAVA_HOME " ]; then
36
+ JAR_CMD=" $JAVA_HOME /bin/jar"
37
+ else
38
+ JAR_CMD=" jar"
39
+ fi
40
+
35
41
# First check if we have a dependencies jar. If so, include binary classes with the deps jar
36
42
if [ -f " $ASSEMBLY_DIR " /spark-assembly* hadoop* -deps.jar ]; then
37
43
CLASSPATH=" $CLASSPATH :$FWDIR /core/target/scala-$SCALA_VERSION /classes"
@@ -44,33 +50,50 @@ if [ -f "$ASSEMBLY_DIR"/spark-assembly*hadoop*-deps.jar ]; then
44
50
CLASSPATH=" $CLASSPATH :$FWDIR /sql/catalyst/target/scala-$SCALA_VERSION /classes"
45
51
CLASSPATH=" $CLASSPATH :$FWDIR /sql/core/target/scala-$SCALA_VERSION /classes"
46
52
CLASSPATH=" $CLASSPATH :$FWDIR /sql/hive/target/scala-$SCALA_VERSION /classes"
53
+ CLASSPATH=" $CLASSPATH :$FWDIR /yarn/stable/target/scala-$SCALA_VERSION /classes"
47
54
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)
50
56
else
51
57
# Else use spark-assembly jar from either RELEASE or assembly directory
52
58
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 )
54
60
else
55
- ASSEMBLY_JAR=` ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* .jar`
61
+ ASSEMBLY_JAR=$( ls " $ASSEMBLY_DIR " /spark-assembly* hadoop* .jar 2> /dev/null )
56
62
fi
57
- CLASSPATH=" $CLASSPATH :$ASSEMBLY_JAR "
58
63
fi
59
64
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
+
60
77
# 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.
62
79
# Both sbt and maven will populate "lib_managed/jars/" with the datanucleus jars when Spark is
63
80
# built with Hive, so first check if the datanucleus jars exist, and then ensure the current Spark
64
81
# assembly is built for Hive, before actually populating the CLASSPATH with the jars.
65
82
# 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
71
95
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 "
74
97
fi
75
98
fi
76
99
90
113
# Add hadoop conf dir if given -- otherwise FileSystem.*, etc fail !
91
114
# Note, this assumes that there is either a HADOOP_CONF_DIR or YARN_CONF_DIR which hosts
92
115
# the configurtion files.
93
- if [ " x " != " x $HADOOP_CONF_DIR " ]; then
116
+ if [ -n " $HADOOP_CONF_DIR " ]; then
94
117
CLASSPATH=" $CLASSPATH :$HADOOP_CONF_DIR "
95
118
fi
96
- if [ " x " != " x $YARN_CONF_DIR " ]; then
119
+ if [ -n " $YARN_CONF_DIR " ]; then
97
120
CLASSPATH=" $CLASSPATH :$YARN_CONF_DIR "
98
121
fi
99
122
0 commit comments