当前位置:网站首页>一篇看懂:IDEA 使用scala 编写wordcount程序 并生成jar包 实测
一篇看懂:IDEA 使用scala 编写wordcount程序 并生成jar包 实测
2022-07-25 10:27:00 【fatfatmomo】
准备工作:
此时在你的PC上,你的JDK应该已经安装配置好JDK1.8版本。
①首先官网下载IDEA(建议Ultimate版) https://www.jetbrains.com/idea/download/#section=windows
②从 http://idea.lanyus.com/ 获得注册码或其他各种方式破解(个人用学生版,未测试过这些网站)
③打开IDEA,安装sbt和scala插件,file-settings-Plugins直接搜scala和sbt安装即可。


④新建工程,选择scala->sbt;

选择适合的JDK和Scala版本;这里的版本一定要对应,JDK最好是1.8版,Scala最好不要是2.12.x以上,目前2.12及以上应该是到了spark2.4版本才支持(跟你要提交作业的spark集群的版本对应)。

到此建立工程完毕。
写程序并打包:
①编写scala程序,src->main->scala右键,new->scala class;

选择Kind为Object;

然后输入你的程序。
package com.hq
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
object wordcount {
def main(args: Array[String]){
if (args.length < 1) {
System.err.println("Usage:")
System.exit(1)
}
val conf = new SparkConf()
// sc是Spark Context,指的是“上下文”,也就是我们运行的环境,需要把conf当参数传进去;
val sc = new SparkContext(conf)
//通过sc获取一个(hdfs上的)文本文件,args(0)就是我们控制台上传入的参数,local运行的话就是传入本地一个文本的path
val input = sc.textFile(args(0))
//下面就是wordcount具体的执行代码
val lines=input.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_+_)
lines.saveAsTextFile(args(1))
sc.stop()
}
}
②设置build.sbt文件
name:="Wordcount"
version:="0.1"
scalaVersion:="2.11.0"
libraryDependencies+="org.apache.spark"%%"spark-core"%"2.3.0"
③打包,File->Project Structure->Artifacts,点“+”->JAR->From……;

选择module和mainclass,JAR files from libraries选择第二项(网上都让选第一项,然而选第一项我挂了);

勾选include in project build,点ok;

然后Build-Build Artifacts生成jar包,如果已有META-INF生成了,必须删除后再build。

至此打包完成。
边栏推荐
- 基于cornerstone.js的dicom医学影像查看浏览功能
- 一文读懂小程序的生命周期和路由跳转
- 【域泛化】2022 IJCAI领域泛化教程报告
- 【flask高级】结合源码解决flask经典报错:Working outside of application context
- Visual thematic map of American airport go style: ArcGIS Pro version
- 爬虫基础一
- 学习路之PHP--Phpstudy 提示 Mysqld.Exe: Error While Setting Value ‘NO_ENGINE_SUBSTITUTION 错误的解决办法
- [动态规划] 70. 爬楼梯
- HCIA experiment (08)
- Learn NLP with Transformer (Chapter 2)
猜你喜欢

Flask框架——消息闪现

Code representation learning: introduction to codebert and other related models

哥廷根大学提出CLIPSeg:一个使用文本和图像prompt能同时作三个分割任务的模型

AI system frontier dynamics issue 43: ONEFLOW V0.8.0 officially released; GPU finds human brain connections; AI doctoral online crowdfunding research topic

HCIA experiment (10) nat

Flask框架——Session与Cookie

redis 哨兵,高可用的执行者

Learn NLP with Transformer (Chapter 7)

100W了!
Learn NLP with Transformer (Chapter 4)
随机推荐
HCIA experiment (06)
[cloud enjoys freshness] community weekly · Vol 72 - the first opening ceremony of the 2022 Huawei developer competition in China was launched; Huawei cloud koomessage is in hot public beta
Esp8266 uses drv8833 drive board to drive N20 motor
PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
From the perspective of open source, analyze the architecture design of SAP classic ERP that will not change in 30 years
2021 scenery written examination summary
B2B2C多商户系统功能丰富,极易二开!!!
Learn NLP with Transformer (Chapter 6)
NB-IOT控制液晶屏(日期的设置与读取)
Google Earth Engine——统计逐年土地分类的频率
【高并发】通过源码深度分析线程池中Worker线程的执行流程
HCIA experiment (09)
Openstack skyline component installation
Reinforcement Learning 强化学习(三)
BeautifulSoup的一些用法
史上最全的立创元器件封装库导入AD详细教程(一直白嫖一直爽)
Flask framework - session and cookies
Signal integrity (SI) power integrity (PI) learning notes (XXXIII) 102 general design rules to minimize signal integrity problems
2021 CEC written examination summary
哥廷根大学提出CLIPSeg:一个使用文本和图像prompt能同时作三个分割任务的模型