40

I've downloaded the prebuild version of spark 1.4.0 without hadoop (with user-provided Haddop). When I ran the spark-shell command, I got this error:

> Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/
FSDataInputStream
        at org.apache.spark.deploy.SparkSubmitArguments$$anonfun$mergeDefaultSpa
rkProperties$1.apply(SparkSubmitArguments.scala:111)
        at org.apache.spark.deploy.SparkSubmitArguments$$anonfun$mergeDefaultSpa
rkProperties$1.apply(SparkSubmitArguments.scala:111)
        at scala.Option.getOrElse(Option.scala:120)
        at org.apache.spark.deploy.SparkSubmitArguments.mergeDefaultSparkPropert
ies(SparkSubmitArguments.scala:111)
        at org.apache.spark.deploy.SparkSubmitArguments.<init>(SparkSubmitArgume
nts.scala:97)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:106)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.fs.FSDataInputStr
eam
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        ... 7 more

I've searched on Internet, it is said that HADOOP_HOME has not been set yet in spark-env.cmd. But I cannot find spark-env.cmd in the spark installation folder. I've traced the spark-shell command and it seems that there are no HADOOP_CONFIG in there. I've tried to add the HADOOP_HOME on environment variable but it still give the same exception.

Actually I don't really using the hadoop. I downloaded hadoop as a workaround as suggested in this question

I am using windows 8 and scala 2.10.

Any help will be appreciated. Thanks.

Community
  • 1
  • 1
David
  • 698
  • 1
  • 7
  • 12

17 Answers17

46

The "without Hadoop" in the Spark's build name is misleading: it means the build is not tied to a specific Hadoop distribution, not that it is meant to run without it: the user should indicate where to find Hadoop (see https://spark.apache.org/docs/latest/hadoop-provided.html)

One clean way to fix this issue is to:

  1. Obtain Hadoop Windows binaries. Ideally build them, but this is painful (for some hints see: Hadoop on Windows Building/ Installation Error). Otherwise Google some up, for instance currently you can download 2.6.0 from here: http://www.barik.net/archive/2015/01/19/172716/
  2. Create a spark-env.cmd file looking like this (modify Hadoop path to match your installation): @echo off set HADOOP_HOME=D:\Utils\hadoop-2.7.1 set PATH=%HADOOP_HOME%\bin;%PATH% set SPARK_DIST_CLASSPATH=<paste here the output of %HADOOP_HOME%\bin\hadoop classpath>
  3. Put this spark-env.cmd either in a conf folder located at the same level as your Spark base folder (which may look weird), or in a folder indicated by the SPARK_CONF_DIR environment variable.
Community
  • 1
  • 1
tiho
  • 6,655
  • 3
  • 31
  • 31
  • 1
    I followed steps described in https://spark.apache.org/docs/latest/hadoop-provided.html and chose 1st case with 'hadoop' binary is on your PATH, but I'm still getting the same issue. I've already added HADOOP_HOME in my environment variables, that's why I don't see any reason to set this variable in script. Could give me some idea why this problem still appear? – Ray Aug 11 '15 at 16:51
  • I understand my problem, but I have one question: is it possible to invoke in windows cmd file $(hadoop classpath) in the same way as in linux bash file? – Ray Aug 11 '15 at 17:57
  • @Ray wish I could help, but I'm no expert, all I can say is the above worked for me... I'm sure there's a way to automatically call "hadoop classpath" in spark-env.cmd to avoid the manual copy/paste, but I didn't look into it. Good luck! – tiho Aug 25 '15 at 18:39
  • It should work, class path are defined here: https://github.com/apache/spark/blob/284e29a870bbb62f59988a5d88cd12f1b0b6f9d3/launcher/src/main/java/org/apache/spark/launcher/AbstractCommandBuilder.java#L213 – Thomas Decaux Dec 26 '15 at 22:11
21

I had the same problem, in fact it's mentioned on the Getting started page of Spark how to handle it:

### in conf/spark-env.sh ###

# If 'hadoop' binary is on your PATH
export SPARK_DIST_CLASSPATH=$(hadoop classpath)

# With explicit path to 'hadoop' binary
export SPARK_DIST_CLASSPATH=$(/path/to/hadoop/bin/hadoop classpath)

# Passing a Hadoop configuration directory
export SPARK_DIST_CLASSPATH=$(hadoop --config /path/to/configs classpath)

If you want to use your own hadoop follow one of the 3 options, copy and paste it into spark-env.sh file :

1- if you have the hadoop on your PATH

2- you want to show hadoop binary explicitly

3- you can also show hadoop configuration folder

http://spark.apache.org/docs/latest/hadoop-provided.html

Hamed MP
  • 5,443
  • 3
  • 39
  • 37
21

I too had the issue,

export SPARK_DIST_CLASSPATH=`hadoop classpath`

resolved the issue.

Jimson James
  • 2,937
  • 6
  • 43
  • 78
5

I ran into the same error when trying to get familiar with spark. My understanding of the error message is that while spark doesn't need a hadoop cluster to run, it does need some of the hadoop classes. Since I was just playing around with spark and didn't care what version of hadoop libraries are used, I just downloaded a spark binary pre-built with a version of hadoop (2.6) and things started working fine.

Rohith
  • 2,043
  • 1
  • 17
  • 42
5

linux

ENV SPARK_DIST_CLASSPATH="$HADOOP_HOME/etc/hadoop/*:$HADOOP_HOME/share/hadoop/common/lib/*:$HADOOP_HOME/share/hadoop/common/*:$HADOOP_HOME/share/hadoop/hdfs/*:$HADOOP_HOME/share/hadoop/hdfs/lib/*:$HADOOP_HOME/share/hadoop/hdfs/*:$HADOOP_HOME/share/hadoop/yarn/lib/*:$HADOOP_HOME/share/hadoop/yarn/*:$HADOOP_HOME/share/hadoop/mapreduce/lib/*:$HADOOP_HOME/share/hadoop/mapreduce/*:$HADOOP_HOME/share/hadoop/tools/lib/*"

windows

set SPARK_DIST_CLASSPATH=%HADOOP_HOME%\etc\hadoop\*;%HADOOP_HOME%\share\hadoop\common\lib\*;%HADOOP_HOME%\share\hadoop\common\*;%HADOOP_HOME%\share\hadoop\hdfs\*;%HADOOP_HOME%\share\hadoop\hdfs\lib\*;%HADOOP_HOME%\share\hadoop\hdfs\*;%HADOOP_HOME%\share\hadoop\yarn\lib\*;%HADOOP_HOME%\share\hadoop\yarn\*;%HADOOP_HOME%\share\hadoop\mapreduce\lib\*;%HADOOP_HOME%\share\hadoop\mapreduce\*;%HADOOP_HOME%\share\hadoop\tools\lib\*
4

Enter into SPARK_HOME -> conf

copy spark-env.sh.template file and rename it to spark-env.sh Inside this file you can set the parameters for spark.

Kshitij Kulshrestha
  • 2,032
  • 1
  • 20
  • 27
  • Thanks for your response.. any idea which variable should i modify? I've rename it to spark-env.cmd too because I am using windows and add "set HADOOP_CONF_DIR=*path" but it gives the same exception.. – David Jun 18 '15 at 08:12
  • Firstly, try to Set HADOOP_HOME in spark-env.cmd and re run it, but if again the same problem persist, then export hadoop-common jar file on the spark classpath in the same configuration file. – Kshitij Kulshrestha Jun 18 '15 at 08:17
  • I've set the HADOOP_HOME and copy hadoop-common.jar to both lib and conf folder.. but still no luck :( – David Jun 18 '15 at 08:52
  • Don't just copy pass their class path too - eg. export SPARK_CLASSPATH=$SPARK_CLASSPATH:hadoop-common.jar – Kshitij Kulshrestha Jun 18 '15 at 09:01
3

Run below from your package dir just before running spark-submit -

export SPARK_DIST_CLASSPATH=`hadoop classpath`
Martin
  • 2,411
  • 11
  • 28
  • 30
1

I finally find a solution to remove the exception.

In spark-class2.cmd, add :

set HADOOP_CLASS1=%HADOOP_HOME%\share\hadoop\common\*
set HADOOP_CLASS2=%HADOOP_HOME%\share\hadoop\common\lib\*
set HADOOP_CLASS3=%HADOOP_HOME%\share\hadoop\mapreduce\*
set HADOOP_CLASS4=%HADOOP_HOME%\share\hadoop\mapreduce\lib\*
set HADOOP_CLASS5=%HADOOP_HOME%\share\hadoop\yarn\*
set HADOOP_CLASS6=%HADOOP_HOME%\share\hadoop\yarn\lib\*
set HADOOP_CLASS7=%HADOOP_HOME%\share\hadoop\hdfs\*
set HADOOP_CLASS8=%HADOOP_HOME%\share\hadoop\hdfs\lib\*

set CLASSPATH=%HADOOP_CLASS1%;%HADOOP_CLASS2%;%HADOOP_CLASS3%;%HADOOP_CLASS4%;%HADOOP_CLASS5%;%HADOOP_CLASS6%;%HADOOP_CLASS7%;%HADOOP_CLASS8%;%LAUNCH_CLASSPATH%

Then, change :

"%RUNNER%" -cp %CLASSPATH%;%LAUNCH_CLASSPATH% org.apache.spark.launcher.Main %* > %LAUNCHER_OUTPUT%

to :

"%RUNNER%" -Dhadoop.home.dir=*hadoop-installation-folder* -cp %CLASSPATH% %JAVA_OPTS% %*

It works fine with me, but I'm not sure this is the best solution.

David
  • 698
  • 1
  • 7
  • 12
1

You should add these jars in you code:

  1. common-cli-1.2.jar
  2. hadoop-common-2.7.2.jar
Alex Bravo
  • 1,601
  • 2
  • 24
  • 40
0

Thank you so much. That worked great, but I had to add the spark jars to the classpath as well: ;c:\spark\lib* Also, the last line of the cmd file is missing the word "echo"; so it should say: echo %SPARK_CMD%

Emul
  • 41
  • 2
0

I had the same issue ....Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/ FSDataInputStream at org.apache.spark.deploy.SparkSubmitArguments$$anonfun$mergeDefaultSpa rkProperties$1.apply(SparkSubmitArguments.scala:111)... Then I realized that I had installed the spark version without hadoop. I installed the "with-hadoop" version the problem went away.

Mayukh
  • 117
  • 1
  • 4
0

for my case

running spark job locally differs from running it on cluster. on cluster you might have a different dependency/context to follow. so essentially in your pom.xml you might have dependencies declared as provided.

when running locally, you don't need these provided dependencies. just uncomment them and rebuild again.

zinking
  • 5,561
  • 5
  • 49
  • 81
0

I encountered the same error. I wanted to install spark on my windows PC and therefore downloaded the without hadoop version of spark, but turns out you need the hadoop libraries! so download any hadoop spark version and set the environment variables.

0

I got this error because the file was copied from Windows. Resolve it using

dos2unix file_name
Shikkou
  • 545
  • 7
  • 22
0

I think you need spark-core dependency of maven. It worked fine for me.

hardik
  • 23
  • 4
0

I used:

export SPARK_HOME=/opt/cloudera/parcels/SPARK2/lib/spark2 export HADOOP_MAPRED_HOME=/opt/cloudera/parcels/CDH/lib/hadoop-0.20-mapreduce

It's work for me!

0

I added hadoop-client-runtime-3.3.2.jar to my user library.

MustardMan
  • 43
  • 1
  • 7