在Intellij IDEA上使用Maven构建Spark应用(Scala)
前言
之前在进行Spark应用程序开发时,一直是稀里糊涂的,只要能用就行。最近刚好的空就专门翻了一些文档(文档的相关链接已在文中贴出,部分链接的访问可能需要科学上网),研究一下如何在Intellij IDEA上进行Spark应用程序开发。 除了我之前手动加载依赖库(依赖库文件已经事先下载完毕)的方式,在Spark官方文档中又提供了两种思路:SBT、Maven。由于我个人开发Spark应用程序时更偏爱Intellij IDEA,这边我简单的介绍下基于它使用Mave构建的方法(sbt的方式暂时还没研究,先放一边,有机会补上)。
官方文档初探
在IDEA上如何使用Maven构建Spark应用,在官网链接中的IDE Setup–>IntelliJ中已经做了简单的概述,内容如下:
To create a Spark project for IntelliJ: 1、Download IntelliJ and install the Scala plug-in for IntelliJ. 2、Go to File -> Import Project, locate the spark source directory, and select “Maven Project”. 3、In the Import wizard, it’s fine to leave settings at their default. However it is usually useful to enable “Import Maven projects automatically”, since changes to the project structure will automatically update the IntelliJ project. 4、As documented in Building Spark, some build configurations require specific profiles to be enabled. The same profiles that are enabled with -P[profile name] above may be enabled on the Profiles screen in the Import wizard. For example, if developing for Hadoop 2.7 with YARN support, enable profiles yarn and hadoop-2.7. These selections can be changed later by accessing the “Maven Projects” tool window from the View menu, and expanding the Profiles section.
使用Maven构建应用的两种方式
基于这样的思路,我找到了两种使用Maven构建应用程序的方式。在阅读一下内容时,我觉得不熟悉Maven的同学最好简单的阅读一下Maven的相关概念,这篇博给了我很大的帮助。
方式一
该方法是基本使用构建java应用程序的方式构建的,以下两篇博客已经讲的很详细了,大家可做参考:
-
。 :这篇博客中带有视频演示,简单通俗。
方式二
该方法使用scala插件的方式构建,我个人更倾向于这一种,以下两篇文章已经做了很多详细的介绍:
结合这两篇文章的内容,我会再做一些修改,构建更适合我个人使用习惯的使用方式(后期补上)。
总结
上一篇:
JS实现多线程数据分片下载