java.lang.ClassNotFoundException: com.datastax.spark.connector.rdd.partitioner.CassandraPartition。

问题描述 投票:0回答:1

我已经使用Cassandra工作了一段时间,现在我正在尝试设置spark和spark-cassandra-connector。我在Windows 10中使用IntelliJ IDEA来做这件事(第一次使用IntelliJ IDEA和Scala)。

build.gradle

apply plugin: 'scala'
apply plugin: 'idea'
apply plugin: 'eclipse'

repositories {
    mavenCentral()

    flatDir {
        dirs 'runtime libs'
    }
}

idea {
    project {
        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

dependencies {
    compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.4.5'
    compile group: 'org.apache.spark', name: 'spark-sql_2.11', version: '2.4.5'
    compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.12'
    compile group: 'com.datastax.spark', name: 'spark-cassandra-connector_2.11', version: '2.5.0'
    compile group: 'log4j', name: 'log4j', version: '1.2.17'
}

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:12.0.1'
    }
}

compileScala.targetCompatibility = "1.8"
compileScala.sourceCompatibility = "1.8"

jar {
    zip64 true
    archiveName = "ModuleName.jar"
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest {
        attributes 'Main-Class': 'org.module.ModuelName'
    }
    exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'

}

模块名称.scala

package org.module
import org.apache.spark.sql.SparkSession
import com.datastax.spark.connector._
import org.apache.spark.sql.types.TimestampType

object SentinelSparkModule {

  case class Document(id: Int, time: TimestampType, data: String)

  def main(args: Array[String]) {
    val spark = SparkSession.builder
      .master("spark://192.168.0.3:7077")
      .appName("App")
      .config("spark.cassandra.connection.host", "127.0.0.1")
      .config("spark.cassandra.connection.port", "9042")
      .getOrCreate()

    //I'm trying it without [Document] since it throws 'Failed to map constructor parameter id in
    //org.module.ModuleName.Document to a column of keyspace.table'

    val documentRDD = spark.sparkContext
      .cassandraTable/*[Document]*/("keyspace", "table")
      .select()
    documentRDD.take(10).foreach(println)
    spark.stop()
 }
}

我有一个运行的火花主在 火花:/192.168.0.3:7077。 和那个主人的工人,但我还没有尝试过。submit 工作在控制台中是一个编译过的jar,我只是想让它在IDE中工作。

我想在IDE中实现它的工作。

scala apache-spark cassandra datastax spark-cassandra-connector
1个回答
1
投票

Cassandra连接器的jar需要被添加到... 阶级斗争. 一种方法是构建一个包含所有所需依赖项的uber jar,并提交给集群。

请参考。用Gradle构建一个uberjar

另外,请确保你把 scope 在您的构建文件中,从 compileprovided 除cassandra连接器外的所有罐子。

参考文献。https:/reflectoring.iomaven-scopes-gradle-configurations。

© www.soinside.com 2019 - 2024. All rights reserved.