当前位置:网站首页>Understanding: idea uses Scala to write wordcount programs and generate jar packages
Understanding: idea uses Scala to write wordcount programs and generate jar packages
2022-07-25 11:24:00 【fatfatmomo】
preparation :
At this time in your PC On , Yours JDK It should have been installed and configured JDK1.8 edition .
① First download on the official website IDEA( Suggest Ultimate edition ) https://www.jetbrains.com/idea/download/#section=windows
② from http://idea.lanyus.com/ Get the registration code or other ways to crack ( Personal student edition , Have not tested these websites )
③ open IDEA, install sbt and scala plug-in unit ,file-settings-Plugins Direct search scala and sbt Can be installed .


④ New project , choice scala->sbt;

Choose the right JDK and Scala edition ; The version here must correspond to ,JDK It is best to 1.8 edition ,Scala It's better not to be 2.12.x above , at present 2.12 And above should be arrived spark2.4 Version only ( To submit your homework spark The version of the cluster corresponds to ).

Now the establishment project is completed .
Write programs and package :
① To write scala Program ,src->main->scala Right click ,new->scala class;

choice Kind by Object;

Then enter your program .
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 yes Spark Context, refer to “ Context ”, That is, the environment in which we run , Need to put conf When parameters are passed in ;
val sc = new SparkContext(conf)
// adopt sc Get one (hdfs Upper ) text file ,args(0) It is the parameter passed in from our console ,local If it runs, it will pass in a local text path
val input = sc.textFile(args(0))
// The following is wordcount Specific execution code
val lines=input.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_+_)
lines.saveAsTextFile(args(1))
sc.stop()
}
}
② Set up build.sbt file
name:="Wordcount"
version:="0.1"
scalaVersion:="2.11.0"
libraryDependencies+="org.apache.spark"%%"spark-core"%"2.3.0"
③ pack ,File->Project Structure->Artifacts, spot “+”->JAR->From……;

choice module and mainclass,JAR files from libraries Select the second term ( You can choose the first item online , However, I hung up on the first item );

Check include in project build, spot ok;

then Build-Build Artifacts Generate jar package , If already META-INF Generated , Must be deleted before build.

So far, the packaging is complete .
边栏推荐
- Learn NLP with Transformer (Chapter 1)
- Redis sentry, high availability executor
- HCIP(12)
- 【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源
- LVS负载均衡之LVS-NAT与LVS-DR模式原理详解
- 【flask高级】结合源码详解flask的运行机制(出入栈)
- SQL语言(三)
- [information system project manager] thought map series essence summary
- syncronized锁升级的过程
- [flask advanced] combined with the source code, explain the operation mechanism of flask (in and out of the stack)
猜你喜欢

Reinforcement Learning 强化学习(四)

BGP federal experiment

Review recitation finishing version

Shell 脚本参数传递时有 \r 换行符问题

Learn NLP with Transformer (Chapter 5)

Learn NLP with Transformer (Chapter 7)

ArcMap无法启动解决方法

【flask高级】结合源码解决flask经典报错:Working outside of application context

Nowcodertop7-11 - continuous updating

机智云物联网平台 STM32 ESP8266-01S 简单无线控灯
随机推荐
100W!
从开源的视角,解析SAP经典ERP “三十年不用变”的架构设计
How to notify users of wechat applet version update?
HCIA experiment (09)
Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error
HCIP(13)
Understand the life cycle and route jump of small programs
Learn NLP with Transformer (Chapter 5)
Reinforcement Learning 强化学习(四)
Nowcodertop7-11 - continuous updating
Several common PCB surface treatment technologies!
Tree dynamic programming
HCIP (01)
学习路之PHP--TP5.0使用中文当别名,报“不支持的数据表达式”
Learn NLP with Transformer (Chapter 8)
ESP8266 使用 DRV8833驱动板驱动N20电机
企业实践开源的动机
Digital twin everything can be seen | connecting the real world and digital space
Learn NLP with Transformer (Chapter 4)
HDD Hangzhou station full experience