本文介绍了错误而执行Scala的构建与星火1.5.2和Scala 2.11.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容的简单的斯卡拉对象文件:

 进口org.apache.spark.SparkContext
进口org.apache.spark.SparkContext._
进口org.apache.spark.SparkConf
对象X {
      高清主(参数:数组[字符串]){        VAL PARAMS =地图[字符串,字符串](
            ABC - > 22)
      的println(创建星火配置);
      VAL CONF =新SparkConf()。setAppName(X)
      VAL SC =新SparkContext(CONF)
      VAL txtFileLines = sc.textFile(/ tmp目录/ x.txt,2).cache()
      VAL数= txtFileLines.count()
      的println(计数+计数)
    }
}

我build.sbt如下:

 名称:=X版本:=1.0scalaVersion:=2.11.7libraryDependencies + =org.apache.spark%%火花核%1.5.2%规定

我然后做SBT包来创建 x.jar 目标/斯卡拉2.11 /

当我执行上述code为:
火花提交--class点¯x--master本地[2] x.jar
我收到以下错误:

 创建星火配置
异常的线程主java.lang.NoSuchMethodError:斯卡拉preDEF $ .ArrowAssoc(Ljava /郎/对象;)Ljava /郎/对象;
    在扫地$。主要(Sweeper.scala:14)
    在Sweeper.main(Sweeper.scala)
    在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)
    在org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:674)
    在org.apache.spark.deploy.SparkSubmit $ .doRunMain $ 1(SparkSubmit.scala:180)
    在org.apache.spark.deploy.SparkSubmit $ .submit(SparkSubmit.scala:205)
    在org.apache.spark.deploy.SparkSubmit $。主要(SparkSubmit.scala:120)
    在org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)


解决方案

当你在你的项目使用Scala 2.11。您应该使用的火花核心库构建斯卡拉2.11。
可以从这里 http://mvnrepository.com/search?q=Spark

请参阅项目火花core_2.11罐子。

I have a simple scala object file with the following content:

import org.apache.spark.SparkContext  
import org.apache.spark.SparkContext._ 
import org.apache.spark.SparkConf  


object X { 
      def main(args: Array[String]) {

        val params = Map[String, String](
            "abc" -> "22",)
      println("Creating Spark Configuration");
      val conf = new SparkConf().setAppName("X")
      val sc = new SparkContext(conf)
      val txtFileLines = sc.textFile("/tmp/x.txt", 2).cache()
      val count = txtFileLines.count()
      println("Count" + count)
    }
}

My build.sbt looks like:

name := "x"

version := "1.0"

scalaVersion := "2.11.7"

libraryDependencies += "org.apache.spark" %% "spark-core" % "1.5.2" % "provided"

I then do sbt package to create x.jar under target/scala-2.11/

When I execute the above code as:spark-submit --class X --master local[2] x.jarI get the following error:

Creating Spark Configuration
Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.ArrowAssoc(Ljava/lang/Object;)Ljava/lang/Object;
    at Sweeper$.main(Sweeper.scala:14)
    at Sweeper.main(Sweeper.scala)
    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$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:674)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

As you are using Scala 2.11 in your project. You should use spark core library build for Scala 2.11. Can download spark-core_2.11 from here http://mvnrepository.com/search?q=Spark

Refer spark-core_2.11 jar in project.

这篇关于错误而执行Scala的构建与星火1.5.2和Scala 2.11.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 14:53