线程“主”中的异常java.lang.NoClassDefFoundError:org / joda / time / DateTime Spark

时间:2018-08-16 19:03:14

标签: java apache-spark exception cassandra rdd

我想使用Java中的Spark从Cassandra数据库中读取一条记录。这是我的代码。

import com.datastax.driver.core.Session;
import com.datastax.spark.connector.japi.CassandraJavaUtil.*;
import com.datastax.spark.connector.japi.CassandraRow;
import org.apache.commons.lang3.StringUtils;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import java.lang.reflect.Field;
import java.util.*;
import static com.datastax.spark.connector.japi.CassandraJavaUtil.*;

public class ProvaCass {
    public static void main (String[] args) {

        SparkConf conf = new SparkConf(true)
                .set("spark.cassandra.connection.host", "127.0.0.1")
                .set("spark.cassandra.auth.username", "cassandra")
                .set("spark.cassandra.auth.password", "cassandra");
        conf.setAppName("Java API demo");
        conf.setMaster("local[4]");
        JavaSparkContext sc = new JavaSparkContext(conf);

        System.out.println("PRIMA");
        JavaRDD<String> cassandraRowsRDD = javaFunctions(sc).cassandraTable("prova", "emp")
                .map(new Function<CassandraRow, String>() {
                    @Override
                    public String call(CassandraRow cassandraRow) throws Exception {
                        return cassandraRow.toString();
                    }
                });
        String l=cassandraRowsRDD.first();
        System.out.println("Data as CassandraRows: \n" +l);
    }
}

我正确添加了(?)connetor spark-cassandra(文件.jar),然后编写了代码,并从this site复制了代码以测试我的代码。我在本地的cassandra db表中的一个表中输入了一条记录,发现该记录存在。 当我运行程序时它不起作用,并且我有这个exception。能否请您一步一步告诉我如何解决?我不知道该怎么想,谢谢....

  

线程“主”中的异常java.lang.NoClassDefFoundError:   org / joda / time / DateTime位于java.lang.Class.getDeclaredMethods0(本机   方法)在java.lang.Class.privateGetDeclaredMethods(Class.java:2701)     在java.lang.Class.getDeclaredMethod(Class.java:2128)在   java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1575)     在java.io.ObjectStreamClass.access $ 1700(ObjectStreamClass.java:79)     在java.io.ObjectStreamClass $ 2.run(ObjectStreamClass.java:508)在   java.io.ObjectStreamClass $ 2.run(ObjectStreamClass.java:482)在   java.security.AccessController.doPrivileged(本机方法),位于   java.io.ObjectStreamClass。(ObjectStreamClass.java:482)在   java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:379)在   java.io.ObjectOutputStream.writeClass(ObjectOutputStream.java:1213)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1120)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)     在   scala.collection.immutable.List $ SerializationProxy.writeObject(List.scala:468)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)     在   java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)     在   java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)     在   java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)     在   java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)     在   org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:43)     在   org.apache.spark.serializer.JavaSerializerInstance.serialize(JavaSerializer.scala:100)     在   org.apache.spark.util.ClosureCleaner $ .ensureSerializable(ClosureCleaner.scala:342)     在   org.apache.spark.util.ClosureCleaner $ .org $ apache $ spark $ util $ ClosureCleaner $$ clean(ClosureCleaner.scala:335)     在   org.apache.spark.util.ClosureCleaner $ .clean(ClosureCleaner.scala:159)     在org.apache.spark.SparkContext.clean(SparkContext.scala:2299)处   org.apache.spark.SparkContext.runJob(SparkContext.scala:2073)在   org.apache.spark.rdd.RDD $$ anonfun $ take $ 1.apply(RDD.scala:1358)在   org.apache.spark.rdd.RDDOperationScope $ .withScope(RDDOperationScope.scala:151)     在   org.apache.spark.rdd.RDDOperationScope $ .withScope(RDDOperationScope.scala:112)     在org.apache.spark.rdd.RDD.withScope(RDD.scala:363)在   org.apache.spark.rdd.RDD.take(RDD.scala:1331)在   org.apache.spark.rdd.RDD $$ anonfun $ first $ 1.apply(RDD.scala:1372)在   org.apache.spark.rdd.RDDOperationScope $ .withScope(RDDOperationScope.scala:151)     在   org.apache.spark.rdd.RDDOperationScope $ .withScope(RDDOperationScope.scala:112)     在org.apache.spark.rdd.RDD.withScope(RDD.scala:363)在   org.apache.spark.rdd.RDD.first(RDD.scala:1371)在   org.apache.spark.api.java.JavaRDDLike $ class.first(JavaRDDLike.scala:538)     在   org.apache.spark.api.java.AbstractJavaRDDLike.first(JavaRDDLike.scala:45)     在ProvaCass.main(ProvaCass.java:30)上,由于:   java.lang.ClassNotFoundException:org.joda.time.DateTime在   java.net.URLClassLoader.findClass(URLClassLoader.java:381)在   java.lang.ClassLoader.loadClass(ClassLoader.java:424)在   sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:349)在   java.lang.ClassLoader.loadClass(ClassLoader.java:357)...还有67个

0 个答案:

没有答案