14

I am trying Spark Twitter Streaming example with Scala using Maven but I am getting below error when I run it:

Caused by: java.lang.ClassNotFoundException: org.apache.spark.Logging

Below are my dependencies:

<dependencies>
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.10</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming_2.10</artifactId>
    <version>2.0.0</version>
</dependency> 
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming-twitter_2.11</artifactId>
    <version>1.6.2</version> 
</dependency> 

I know that the Logging has been moved to org.apache.spark.internal.Logging but I don't know if it is the reason , I already tried to change the version of dependencies to the latest one but with no luck.

1
  • have you resolved the issue? Commented Aug 25, 2016 at 1:03

6 Answers 6

17

TLDR;

Class org.apache.spark.Logging is available in Spark version 1.5.2 or lower (though I didn't test on all lower versions) but is not available in versions higher than the same.


It all comes down to using incompatible version of Apache Spark:

1. Let's try to import org.apache.spark.Logging on Spark 2.0.0:

user@ubuntu:~$ /opt/spark/bin/spark-shell
Welcome to
  ____              __
 / __/__  ___ _____/ /__
_\ \/ _ \/ _ `/ __/  '_/
/___/ .__/\_,_/_/ /_/\_\   version 2.0.0
   /_/      
Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101)
scala> import org.apache.spark.Logging
<console>:23: error: object Logging is not a member of package org.apache.spark
import org.apache.spark.Logging
          ^

Class org.apache.spark.Logging is not found.


2. Let's try to import org.apache.spark.Logging on Spark 1.6.2:

(same as above i.e. Class org.apache.spark.Logging is not found.)


3. Let's try to import org.apache.spark.Logging on Spark 1.5.2:

user@ubuntu:~$ /opt/spark-1.5.2-bin-hadoop2.6/bin/spark-shell
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 1.5.2
      /_/
Using Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101)
scala> import org.apache.spark.Logging
import org.apache.spark.Logging

YES! It is available and successfully imported

As you can see that org.apache.spark.Logging which is required by the Spark-Streaming-Twitter, is available in Spark version 1.5.2 or lower, so I would recommend you to use 1.5.2 or a lower version of spark.

Hence, you should replace your maven dependencies with followings: (Assuming that you are using Scala 2.11.x)

<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.11</artifactId>
    <version>1.5.2</version>
</dependency>

<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming_2.11</artifactId>
    <version>1.5.2</version>
</dependency>

<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming-twitter_2.11</artifactId>
    <version>1.6.2</version>
</dependency>

Note that the artifactId: 2.11 refers to scala version and version: 1.5.2 or 1.6.2 refers to the library (spark-core or spark-streaming-twitter) version.

Sign up to request clarification or add additional context in comments.

3 Comments

No way to do this without downgrading Apache Spark version.
I changed to <groupId>org.apache.bahir</groupId> and it works, perfectly works. I don't think downgrading spark is the way forward.
@ypriverol yes. What you did is the right thing. You are welcome to edit my answer or I will do it soon.
10

Good news! There is another dependency that solves this problem, and is compatible with Spark 2.x.

For SBT, use this dependency:

"org.apache.bahir" %% "spark-streaming-twitter" % "2.0.0"

1 Comment

I am using below dependencies but result is same. libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.2.0" // mvnrepository.com/artifact/org.apache.spark/… //libraryDependencies += "org.apache.spark" % "spark-streaming-twitter_2.11" % "1.6.3" % "provided" libraryDependencies+="org.apache.bahir" %% "spark-streaming-twitter" % "2.0.0" //--packages "org.apache.spark:spark-streaming-twitter_2.11:1.6.3" libraryDependencies += "org.apache.spark" % "spark-streaming_2.11" % "2.2.0"
5

I encountered this exception using spark-streaming-kafka_2.11-1.6.3.jar, and solved it by using spark-streaming-kafka-0-8_2.11-2.1.0.jar instead

1 Comment

Worked for me !
2

Without changing version, we can solve the issue.

Download spark-core_2.11-1.5.2.logging.jar from https://raw.githubusercontent.com/swordsmanliu/SparkStreamingHbase/master/lib/spark-core_2.11-1.5.2.logging.jar and paste it in spark\jars folder. Include this jar path in spark-submit command . It solved my issue.

Comments

0

As @ypriverol suggested, change dependency to org.apache.bahir. Apache Bahir provides extensions to number of Apache analytical platforms including Spark.

<dependency>
    <groupId>org.apache.bahir</groupId>
    <artifactId>spark-streaming-twitter_2.11</artifactId>
    <version>2.2.0</version>
</dependency>

Comments

0

Try adding https://mvnrepository.com/artifact/commons-logging/commons-logging as a dependency and build the jar again..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.