在Intellij IDEA上使用Maven构建Spark应用(Scala)

来源:互联网 发布:数据库维护工资多少 编辑:程序博客网 时间:2024/06/10 23:40

    • 前言
    • 官方文档初探
    • 使用Maven构建应用的两种方式
      • 方式一
      • 方式二
    • 总结

前言

之前在进行Spark应用程序开发时,一直是稀里糊涂的,只要能用就行。最近刚好的空就专门翻了一些文档(文档的相关链接已在文中贴出,部分链接的访问可能需要科学上网),研究一下如何在Intellij IDEA上进行Spark应用程序开发。
除了我之前手动加载依赖库(依赖库文件已经事先下载完毕)的方式,在Spark官方文档Useful Developer Tools中又提供了两种思路: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的相关概念,Maven核心概念和日常实践这篇博给了我很大的帮助。

方式一

该方法是基本使用构建java应用程序的方式构建的,以下两篇博客已经讲的很详细了,大家可做参考:

  • 基于IntelliJ IDEA开发Spark的Maven项目——Scala语言
  • Setting up Spark with Maven。
  • How to setup a Spark/Scala App with IntelliJ and Maven:这篇博客中带有视频演示,简单通俗。

方式二

该方法使用scala插件的方式构建,我个人更倾向于这一种,以下两篇文章已经做了很多详细的介绍:

  • Create a Spark Application with Scala using Maven on IntelliJ
  • Create a Scala Maven application to run on Apache Spark cluster on HDInsight

结合这两篇文章的内容,我会再做一些修改,构建更适合我个人使用习惯的使用方式(后期补上)。

总结

在IDEA中构建Spark应用程序的方式有很多种,各有千秋。个人觉得使用者在选择使用方式时,不必过多的拘泥于使用方式上,适合自己以及开发场景的才是最好的方法。最后,向以上博客中所引用的链接的作者们致敬。

阅读全文
0 0
原创粉丝点击