当前位置:网站首页>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 .
边栏推荐
- Digital twin everything can be seen | connecting the real world and digital space
- [information system project manager] thought map series essence summary
- Learn NLP with Transformer (Chapter 8)
- web移动端:touchmove实现局部滚动
- HCIP (01)
- Reinforcement Learning 强化学习(三)
- HCIP(12)
- [recursion] 938. Range and of binary search tree
- ArcMap无法启动解决方法
- 【flask高级】从源码深入理解flask的应用上下文和请求上下文
猜你喜欢

HCIA experiment (07) comprehensive experiment
Learn NLP with Transformer (Chapter 3)

Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs

BeautifulSoup的一些用法

HCIP(12)

推荐系统-协同过滤在Spark中的实现

Some usages of beautifulsoup

How can you use unity without several plug-ins? Unity various plug-ins and tutorial recommendations

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

Stm32cubemx learning record -- installation, configuration and use
随机推荐
There is a newline problem when passing shell script parameters \r
Implementation of recommendation system collaborative filtering in spark
LVS负载均衡之LVS-DR搭建Web群集与LVS结合Keepalived搭建高可用Web群集
[flask advanced] combined with the source code, explain the operation mechanism of flask (in and out of the stack)
玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
Learn NLP with Transformer (Chapter 5)
从开源的视角,解析SAP经典ERP “三十年不用变”的架构设计
Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
LVS load balancing lvs-dr builds Web Clusters and LVS combines with kept to build highly available Web Clusters
HCIA experiment (08)
SQL语言(六)
C# Newtonsoft.Json 高级用法
tensorflow 调用多块GPU的一些错误
txt转csv文件,隔行出现空行
MySQL | GROUP_ The concat function concatenates the values of a column with commas
【flask高级】从源码深入理解flask的应用上下文和请求上下文
Learn NLP with Transformer (Chapter 8)
feign客户端请求之LoadBalancerLifecycle生命周期
Ue4.26 source code version black screen problem of client operation when learning Wan independent server
Database design - Simplified dictionary table [easy to understand]