|
40 | 40 | fi |
41 | 41 | fi |
42 | 42 |
|
43 | | -# Look for the launcher. In non-release mode, add the compiled classes directly to the classpath |
44 | | -# instead of looking for a jar file. |
45 | | -SPARK_LAUNCHER_CP= |
46 | | -if [ -f $SPARK_HOME/RELEASE ]; then |
47 | | - LAUNCHER_DIR="$SPARK_HOME/lib" |
48 | | - num_jars="$(ls -1 "$LAUNCHER_DIR" | grep "^spark-launcher.*\.jar$" | wc -l)" |
49 | | - if [ "$num_jars" -eq "0" -a -z "$SPARK_LAUNCHER_CP" ]; then |
50 | | - echo "Failed to find Spark launcher in $LAUNCHER_DIR." 1>&2 |
51 | | - echo "You need to build Spark before running this program." 1>&2 |
52 | | - exit 1 |
53 | | - fi |
| 43 | +# Find assembly jar |
| 44 | +SPARK_ASSEMBLY_JAR= |
| 45 | +if [ -f "$SPARK_HOME/RELEASE" ]; then |
| 46 | + ASSEMBLY_DIR="$SPARK_HOME/lib" |
| 47 | +else |
| 48 | + ASSEMBLY_DIR="$SPARK_HOME/assembly/target/scala-$SPARK_SCALA_VERSION" |
| 49 | +fi |
54 | 50 |
|
55 | | - LAUNCHER_JARS="$(ls -1 "$LAUNCHER_DIR" | grep "^spark-launcher.*\.jar$" || true)" |
56 | | - if [ "$num_jars" -gt "1" ]; then |
57 | | - echo "Found multiple Spark launcher jars in $LAUNCHER_DIR:" 1>&2 |
58 | | - echo "$LAUNCHER_JARS" 1>&2 |
59 | | - echo "Please remove all but one jar." 1>&2 |
60 | | - exit 1 |
61 | | - fi |
| 51 | +num_jars="$(ls -1 "$ASSEMBLY_DIR" | grep "^spark-assembly.*hadoop.*\.jar$" | wc -l)" |
| 52 | +if [ "$num_jars" -eq "0" -a -z "$SPARK_ASSEMBLY_JAR" ]; then |
| 53 | + echo "Failed to find Spark assembly in $ASSEMBLY_DIR." 1>&2 |
| 54 | + echo "You need to build Spark before running this program." 1>&2 |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +ASSEMBLY_JARS="$(ls -1 "$ASSEMBLY_DIR" | grep "^spark-assembly.*hadoop.*\.jar$" || true)" |
| 58 | +if [ "$num_jars" -gt "1" ]; then |
| 59 | + echo "Found multiple Spark assembly jars in $ASSEMBLY_DIR:" 1>&2 |
| 60 | + echo "$ASSEMBLY_JARS" 1>&2 |
| 61 | + echo "Please remove all but one jar." 1>&2 |
| 62 | + exit 1 |
| 63 | +fi |
62 | 64 |
|
63 | | - SPARK_LAUNCHER_CP="${LAUNCHER_DIR}/${LAUNCHER_JARS}" |
| 65 | +SPARK_ASSEMBLY_JAR="${ASSEMBLY_DIR}/${ASSEMBLY_JARS}" |
| 66 | + |
| 67 | +# Verify that versions of java used to build the jars and run Spark are compatible |
| 68 | +if [ -n "$JAVA_HOME" ]; then |
| 69 | + JAR_CMD="$JAVA_HOME/bin/jar" |
64 | 70 | else |
65 | | - LAUNCHER_DIR="$SPARK_HOME/launcher/target/scala-$SPARK_SCALA_VERSION" |
66 | | - if [ ! -d "$LAUNCHER_DIR/classes" ]; then |
67 | | - echo "Failed to find Spark launcher classes in $LAUNCHER_DIR." 1>&2 |
68 | | - echo "You need to build Spark before running this program." 1>&2 |
| 71 | + JAR_CMD="jar" |
| 72 | +fi |
| 73 | + |
| 74 | +if [ $(command -v "$JAR_CMD") ] ; then |
| 75 | + jar_error_check=$("$JAR_CMD" -tf "$SPARK_ASSEMBLY_JAR" nonexistent/class/path 2>&1) |
| 76 | + if [[ "$jar_error_check" =~ "invalid CEN header" ]]; then |
| 77 | + echo "Loading Spark jar with '$JAR_CMD' failed. " 1>&2 |
| 78 | + echo "This is likely because Spark was compiled with Java 7 and run " 1>&2 |
| 79 | + echo "with Java 6. (see SPARK-1703). Please use Java 7 to run Spark " 1>&2 |
| 80 | + echo "or build Spark with Java 6." 1>&2 |
69 | 81 | exit 1 |
70 | 82 | fi |
71 | | - SPARK_LAUNCHER_CP="$LAUNCHER_DIR/classes" |
72 | 83 | fi |
73 | 84 |
|
74 | 85 | # The launcher library will print arguments separated by a NULL character, to allow arguments with |
|
77 | 88 | CMD=() |
78 | 89 | while IFS= read -d '' -r ARG; do |
79 | 90 | CMD+=("$ARG") |
80 | | -done < <("$RUNNER" -cp "$SPARK_LAUNCHER_CP" org.apache.spark.launcher.Main "$@") |
| 91 | +done < <("$RUNNER" -cp "$SPARK_ASSEMBLY_JAR" org.apache.spark.launcher.Main "$@") |
81 | 92 |
|
82 | 93 | if [ "${CMD[0]}" = "usage" ]; then |
83 | 94 | "${CMD[@]}" |
|
0 commit comments