第一步:新建一個(gè)maven工程
第二部:命名工程名
第三步:新建一個(gè)文件夾,并設(shè)置為sources root
第四步:pom編寫
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cn.spark</groupId>
<artifactId>spark-day01</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
第五步:新建一個(gè)Scala類
注意:此步可能找不到Scala,需要引入
具體步驟為
1.項(xiàng)目構(gòu)建
2.點(diǎn)擊+
3.添加Scala,如果有Scala環(huán)境,會(huì)默認(rèn)識(shí)別版本
最后會(huì)引入Scala,如下
第六步:引入spark相關(guān)jar包
選擇自己的spark安裝包,里邊有jar包目錄
第七步:新建一個(gè)Scala
第八步:編寫代碼驗(yàn)證文章來源:http://www.zghlxwxcb.cn/news/detail-403710.html
package com.cn.wordcount
import org.apache.spark.{SparkConf, SparkContext}
object Driver {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local").setAppName("wordCount")
val sc = new SparkContext(conf)
val data = sc.textFile("hdfs://hadoop01:9000/data", 2)
val result=data.flatMap{line=>line.split(" ")}.map{word=>(word,1)}.reduceByKey((x,y)=>x+y)
// result.foreach(line=>println(line))
result.saveAsTextFile("hdfs://hadoop01:9000/result03")
}
}
第九步:運(yùn)行結(jié)果(打印到控制臺(tái),并且將數(shù)據(jù)存儲(chǔ)到Hadoop中hdfs中)文章來源地址http://www.zghlxwxcb.cn/news/detail-403710.html
到了這里,關(guān)于IDEA新建一個(gè)spark項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!