编译后执行Spark scala程序
我已经在命令行上编译了Spark scala程序。但现在我想执行它。我不想使用Maven或sbt。 这个程序。我用这个命令来执行 scala-cp.“:sparkDIrector/jars/*”字数 但我得到了这个错误 java.lang.NoSuchMethodError:scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;编译后执行Spark scala程序,scala,apache-spark,Scala,Apache Spark,我已经在命令行上编译了Spark scala程序。但现在我想执行它。我不想使用Maven或sbt。 这个程序。我用这个命令来执行 scala-cp.“:sparkDIrector/jars/*”字数 但我得到了这个错误 java.lang.NoSuchMethodError:scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps; import org.apache.spark._ impo
import org.apache.spark._
import org.apache.spark.SparkConf
/** Create a RDD of lines from a text file, and keep count of
* how often each word appears.
*/
object wordcount1 {
def main(args: Array[String]) {
// Set up a SparkContext named WordCount that runs locally using
// all available cores.
println("before conf")
val conf = new SparkConf().setAppName("WordCount")
conf.setMaster("local[*]")
val sc = new SparkContext(conf)
println("after the textfile")
// Create a RDD of lines of text in our book
val input = sc.textFile("book.txt")
println("after the textfile")
// Use flatMap to convert this into an rdd of each word in each line
val words = input.flatMap(line => line.split(' '))
// Convert these words to lowercase
val lowerCaseWords = words.map(word => word.toLowerCase())
// Count up the occurence of each unique word
println("before text file")
val wordCounts = lowerCaseWords.countByValue()
// Print the first 20 results
val sample = wordCounts.take(20)
for ((word, count) <- sample) {
println(word + " " + count)
}
sc.stop()
}
}
import org.apache.spark_
导入org.apache.spark.SparkConf
/**从文本文件创建行的RDD,并记录
*每个单词出现的频率。
*/
对象wordcount1{
def main(参数:数组[字符串]){
//设置名为WordCount的SparkContext,使用
//所有可用的核心。
println(“配置前”)
val conf=new SparkConf().setAppName(“WordCount”)
conf.setMaster(“本地[*]”)
val sc=新的SparkContext(配置)
println(“在文本文件之后”)
//在我们的书中创建文本行的RDD
val input=sc.textFile(“book.txt”)
println(“在文本文件之后”)
//使用flatMap将其转换为每行中每个单词的rdd
val words=input.flatMap(line=>line.split(“”))
//将这些单词转换成小写
val lowerCaseWords=words.map(word=>word.toLowerCase())
//计算每个唯一单词的出现次数
println(“文本文件之前”)
val wordCounts=lowerCaseWords.countByValue()
//打印前20个结果
val sample=wordCounts.take(20)
对于从Spark 2.0开始的((字,计数),入口点是SparkSession:
import org.apache.spark.sql.SparkSession
val spark = SparkSession
.builder
.appName("App Name")
.getOrCreate()
然后,您可以访问SparkContext并使用以下命令读取文件:
spark.sparkContext().textFile(yourFileOrURL)
记住在结束时停止会话:
spark.stop()
我建议大家看看这些例子:
然后,要启动应用程序,您必须使用spark submit
:
./bin/spark-submit \
--class <main-class> \
--master <master-url> \
--deploy-mode <deploy-mode> \
--conf <key>=<value> \
... # other options
<application-jar> \
[application-arguments]
我不打算使用spark submit。当我使用scala命令以及所需的类路径和类名时,应用程序不会执行吗?我认为这是不可能的。即使在本地运行,spark也会将您的计算机“作为群集”使用.Spark不仅仅是一堆库,它是一个集群计算系统,它公开了一些API供您使用。
./bin/spark-submit \
--class wordcount1 \
--master local \
/path/to/your.jar