在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. 【Weiss】【第03章】链表例程

    这种基础例程,如之前所提,会有一个实现和一个简单的测试代码. 链表其实没什么可说的,其实包括后面的栈和队列也没什么可说的,直接放代码吧. 下面这个是测试代码 #include <iostream ...

  2. linux 执行计划任务crontab

    crontab 一些常用的命令 service crond start //启动服务 service crond stop //关闭服务 service crond restart //重启服务 se ...

  3. 网络安全从入门到精通 (第二章-1) Web安全前端基础

    本文内容: 前端是什么? 前端代码 HTML CSS JS !!!醋成酒的小墨,促成就的小墨,小墨促成就,!!! 1,前端是什么? 网站一般用两部分组成,前端负责展示,后端负责处理请求. 2,前端代码 ...

  4. Socket编程简介

    目录 背景 基础 流程 参考 本文系读书笔记,非深入研究,也无代码,如非所需,请见谅. 哦,这里有份不错的:Linux的SOCKET编程详解 背景 花了好久的时间(大约一周,我太垃圾)看完了一篇英文文 ...

  5. 【开发工具 docker】值得学习的应用容器引擎docker安装

    概述: Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何 ...

  6. 暴力+辗转相除法——N个数求和

    题目来源 PTA 团体程序设计天梯赛-练习集 L1-009 N个数求和 (20分) https://pintia.cn/problem-sets/994805046380707840/problems ...

  7. 如何从零基础开始学习LoadRunner12(一)

    如何从零基础开始学习LoadRunner12(一) 上一篇文章讲到了如何安装LR12的教程,这一篇文章来讲一下怎么利用LoadRunner自带的Sample来学习LoadRunner的基本使用. 首先 ...

  8. [AI开发]零代码公式让你明白神经网络的输入输出

    这篇文章的标题比较奇怪,网上可能很少类似专门介绍神经网络的输入输出相关文章.在我实际工作和学习过程中,发现很有必要对神经网络的输入和输出做一个比较全面地介绍.跟之前博客一样,本篇文章不会出现相关代码或 ...

  9. spring boot项目打war包

    1.如果有本地依赖,添加本地依赖到maven <!--lib目录下的jar包--> <dependency> <groupId>com.dm</groupId ...

  10. Python电影数据分析

    数据说明:MovieLens数据集,它包含来自于943个用户以及精选的1682部电影的100K个电影打分.每个用户至少为20部电影打分,数据类型user id | item id | rating | ...