kafka spark cluster的classnotfoundexception

q5lcpyga  于 2021-06-07  发布在  Kafka
关注(0)|答案(2)|浏览(401)

我正在尝试运行scalaspark2.0.2中的一些.jar文件。在我的SparkKafka集群。代码在这里:

import java.util.HashMap

import org.apache.kafka.clients.producer.{KafkaProducer,ProducerConfig}
   import org.apache.spark.SparkConf
   import org.apache.spark.streaming._
   import org.apache.spark.streaming.kafka._

object sparkKafka{
  def main(args: Array[String]): Unit = {
    if(args.length < 4){
      System.err.println("Usage: sparkKafka <zkQuorum><group> <topics> <numThreads>")
      System.exit(1)
    }

val Array(zkQuorum, group, topics, numThreads) = args
val sparkConf = new SparkConf()
    .setAppName("sparkKafka")
val ssc = new StreamingContext(sparkConf, Seconds(2))
ssc.checkpoint("E:/temp/")

val topicMap = topics.split(",").map((_, numThreads.toInt)).toMap
val lines = KafkaUtils.createStream(ssc, zkQuorum, group, topicMap).map(_._2)
val words = lines.flatMap(_.split(" "))
val wordsCounts = words.map(x => (x, 1L))
    .reduceByKeyAndWindow(_ + _, _ - _, Minutes(10), Seconds(2), 2)
wordsCounts.print()

ssc.start()
ssc.awaitTermination()

}
}
我构建了一个名为kafka-spark.jar的.jar文件,并将其scp到spark2文件夹中的我的节点,这样它就可以读取它了。之后我开始写剧本:

bin/spark-submit  --class "sparkKafka" --master local[4] kafka-spark.jar hdp2.local:2181 group1 Topic-example 1 -verbose

我得到的错误就像在主题标题中说的,或者classnotfoundexception:sparkkafka

[root@hdp2 spark2]# bin/spark-submit  --class "sparkKafka" --master local[4] kafka-spark.jar hdp2.local:2181 group1 Topic-example 1 -verbose
java.lang.ClassNotFoundException: sparkKafka
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.apache.spark.util.Utils$.classForName(Utils.scala:225)
        at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:686)
        at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
        at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

我哪里出错了?我也尝试了我的jar文件的完整路径,但是我得到了.jar找不到或者上面的这个错误。我也试过不用-v,但我觉得没什么区别。如果有人知道哪里有问题就好了。谢谢您!

mitkmikd

mitkmikd1#

你试过这样称呼它吗

bin/spark-submit  --class "sparkKafka" --master local[4] kafka-spark.jar hdp2.local:2181 group1 Topic-example 1 -verbose

如果这不起作用,您可能需要提取kafka-spark.jar的内容,并检查它是否真的包含sparkkafka类。

qhhrdooz

qhhrdooz2#

你在你的sparkkafka.scala里加了包吗?

相关问题