【发布时间】:2016-07-14 23:37:29
【问题描述】:
我正在改造一个现有的包,使其在spark上运行,为了在第三方工具中序列化类,我使用了以下代码:
SparkConf conf = new SparkConf().setAppName("my.app.spark").setMaster("local").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer").set("spark.kryo.registrationRequired", "true");
try {
conf.registerKryoClasses(new Class<?>[]{
Class.forName("my.thirdparty.classes"),
Class.forName("my.thirdparty.classes2")
});
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JavaSparkContext context = new JavaSparkContext(conf);
List<File> txtFiles = new ArrayList<File>();
for(File file: input.listFiles(filter)) {
txtFiles.add(file);
}
JavaRDD<File> distText = context.parallelize(txtFiles);
distText.foreach(
new VoidFunction<File>()
{ public void call(File file) {
processFile(file);
}});
context.close();
当我使用以下命令提交时: spark-submit --class "mypackage.RunWithSpark" --master yarn --driver-memory 6g mypackage.jar
我收到如下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.spark.SparkConf.registerKryoClasses([Ljava/lang/Class;)Lorg/apache/spark/SparkConf;
...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.SparkSubmit$.launch(SparkSubmit.scala:292)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:55)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
我是 Spark 的新手,您能帮忙吗?
谢谢
【问题讨论】:
-
您的集群中的 Spark 版本是多少?
-
它是SPARK 1.0.0,在CDH 5.1.0中,对于java包,我使用maven来配置spark 1.6.1
标签: java apache-spark kryo