在idea中新建工程

删除新项目的src,创建moudle

在父pom中添加spark和scala依赖,我们项目中用scala开发模型,建议scala,开发体验会更好(java、python也可以)

<?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.shaozhiqi.bigdata</groupId>
<artifactId>spark-demo01</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>spark-core</module>
</modules> <properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<scala.version>2.11.7</scala.version>
<spark.version>2.4.3</spark.version>
<encoding>UTF-8</encoding>
</properties>
<dependencies> <dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency> <dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>${spark.version}</version>
</dependency>
</dependencies> </project>

在我们Moudle中配置打包插件

<?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">
<parent>
<artifactId>spark-demo01</artifactId>
<groupId>com.shaozhiqi.bigdata</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>spark-core</artifactId> <build>
<pluginManagement>
<plugins>
<!-- 编译scala的插件 -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 打包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!--you can add you want to need the main class--><!---->
<mainClass>com.shaozhiqi.bigdata.spark.WordCount</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

安装scala开发插件到idea

安装后重启

设置scalasdk,选我们新建的moudle

image.png

新建scala对象

编写代码:

 def main(args: Array[String]): Unit = {
//1.创建配置信息
val conf =new SparkConf().setAppName("wordcount").setMaster("local[*]")
//2.创建sparkcontext
val sc= new SparkContext(conf)
//3.处理业务数据,我们统计每个单词的个数
// 我们要在集群上尝试所以就将textFile的参数参数化,如果在本地执行则写本地的绝对路径
val lines=sc.textFile("G:\\temp\\input.txt")
val words=lines.flatMap(_.split(" "))
val keyMap=words.map((_, 1))
val result =keyMap.reduceByKey(_+_)
result.foreach(println)
//4.关闭连接
sc.stop()
}

本地调测试

(1233,1)
(llll,1)
(hhh,1)
(ddd,2)
(55,2)
(,1)
(kkkk,1)
(jjj,1)

spark本地开发环境搭建及打包配置的更多相关文章

  1. spark-windows(含eclipse配置)下本地开发环境搭建

    spark-windows(含eclipse配置)下本地开发环境搭建   >>>>>>注意:这里忽略JDK的安装,JDK要求是1.8及以上版本,请通过 java  ...

  2. spark JAVA 开发环境搭建及远程调试

    spark JAVA 开发环境搭建及远程调试 以后要在项目中使用Spark 用户昵称文本做一下聚类分析,找出一些违规的昵称信息.以前折腾过Hadoop,于是看了下Spark官网的文档以及 github ...

  3. 手把手教你 Apache DolphinScheduler 本地开发环境搭建 | 中英文视频教程

    点击上方 蓝字关注我们 最近,一些小伙伴反馈对小海豚的本地开发环境搭建过程不太了解,这不就有活跃的贡献者送来新鲜的视频教程!在此感谢@Tianqi-Dotes 的细致讲解 贡献者还贴心地录制了中英文两 ...

  4. 【OpenStack】OpenStack系列1之OpenStack本地开发环境搭建&&向社区贡献代码

    加入OpenStack社区 https://launchpad.net/,注册用户(597092663@qq.com/Admin@123) 修改个人信息,配置SSH keys.OpenPGP keys ...

  5. Windows下基于eclipse的Spark应用开发环境搭建

    原创文章,转载请注明: 转载自www.cnblogs.com/tovin/p/3822985.html 一.软件下载 maven下载安装 :http://10.100.209.243/share/so ...

  6. 本地开发环境搭建(windows)

    一.虚拟器安装 1.概念 ・为什么要搭建搭建模拟环境 在租借服务器前用手中的PC模拟一个服务器的环境,可以打包与团队人员分享 ・什么是Vagrant https://segmentfault.com/ ...

  7. 使用wifi网卡笔记1----网卡选型、开发环境搭建、内核配置

    1.wifi的STA模式和AP模式 Ap(Access Point)模式指的是可以将网卡设置为路由器用来共享流量或有线网络给别人使用, sta模式指的是当做网卡连接路由器上网 (1):AP也就是无线接 ...

  8. Linux巩固记录(1) J2EE开发环境搭建及网络配置

    由于要近期使用hadoop等进行相关任务执行,操作linux时候就多了 以前只在linux上配置J2EE项目执行环境,无非配置下jdk,部署tomcat,再通过docker或者jenkins自动部署上 ...

  9. Spark程序开发-环境搭建-程序编写-Debug调试-项目提交

    1,使用IDEA软件进行开发. 在idea中新建scala project, File-->New-->Project.选择Scala-->Scala 2,在编辑窗口中完成Word ...

随机推荐

  1. [Alg] 文本匹配-单模匹配与多模匹配

    实际场景: 网站的用户发了一些帖子S1, S2,...,网站就要审核一下这些帖子里有没有敏感词. 1. 如果网站想查一下帖子里有没有一个敏感词P,这个文本匹配要怎么做更快? 2. 如果网站想查一下帖子 ...

  2. Core3.1WebApi_ 同源策略_如何支持跨域(转载)

    原文:https://mp.weixin.qq.com/s/id3fOyGrZI9lLx7PKbVYlg

  3. Idea中使用http请求解决中文乱码问题

    以请求百度为例,使用如下代码即可解决: GET https://www.baidu.com User-Agent: Mozilla/.X MetaSr 1.0

  4. NeurIPS 2019 | 基于Co-Attention和Co-Excitation的少样本目标检测

    论文提出CoAE少样本目标检测算法,该算法使用non-local block来提取目标图片与查询图片间的对应特征,使得RPN网络能够准确的获取对应类别对象的位置,另外使用类似SE block的sque ...

  5. 为 .net 生态贡献力量——制作并上传 nuget 包(内有独家彩蛋)

    前言 nuget 是 .net 的常用包管理器,目前已经内置到 Visual Studio 2012 以后的版本.大多数 .net 包都托管在 nuget.org,包括 .net core 框架基础包 ...

  6. 第十四周java实验作业

    实验十四  Swing图形界面组件 实验时间 20178-11-29 1.实验目的与要求 (1) 掌握GUI布局管理器用法: 在java中的GUI应用 程序界面设计中,布局控制通过为容器设置布局管理器 ...

  7. P4147 玉蟾宫 题解

    原题链接 简要题意: 求最大 \(0\) 矩阵.(将字符转化为数字) 本题是模板题,可以用来爆踩.??? 悬线法 来了! 其中绿色是 \(0\),红色是 \(1\). 下面以这个图为例讲一下算法流程. ...

  8. TensorFlow Windows 安装

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 本系列教程将手把手带您从零开始学习Tensorflow,并最终通过 ...

  9. coding++:java-全局异常处理

    本次使用工具:SpringBoot   <version>1.5.19.RELEASE</version> Code: AbstractException: package m ...

  10. gunicorn的作用

    gunicorn是什么: gunicorn是一种unix上被广泛使用的Python WSGI UNIX HTTP Server WSGI是什么: 先说下 WSGI 的表面意思,Web Server G ...