学习笔记:从0开始学习大数据-13. Eclipse+Scala+Maven Spark开发环境配置

上节配置好了spark运行环境,可以通过 spark-shell  在scala语言界面交互执行spark命令

可以参照( https://blog.csdn.net/u010285974/article/details/81840413   Spark-shell执行计算) 这篇文章操作练习

接下来在eclipse ide环境开发spark程序,环境配置费了一翻周折,在此记录,备用

我已安装好了Eclipse2018-09即Eclipse4.9版,而scala for eclipse下载最高提示支持eclipse4.7版,但其实也可以在eclipse4.9中安装成功

1.下载scala for eclipse插件,也可以直接复制网址让eclipse安装

2.Eclipse点击 菜单:帮助-》安装新软件-》新建-》输入以上网址

3.选全部-》下一步—》完成-》等待下载完毕-》重启Eclipse

4.可以测试新建scala project 

编辑一个helloworld程序,测试scala正常可用

5. 新建maven项目 mavenscala

修改项目的pom.xml 增加对spark的支持,另外重要的是修改默认的paranamer-2.3.jar 为版本2.8  删除2.3版的构建路径引用,不然运行spark程序总提示 “-java.lang.ArrayIndexOutOfBoundsException: 10582”的错误,折腾了好多时间

pom.xml 全文如下

<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.linbin</groupId>
  <artifactId>mavenscala</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mavenscala</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-core_2.12</artifactId>
    <version>2.4.0</version>
</dependency>
 <!-- https://mvnrepository.com/artifact/com.thoughtworks.paranamer/paranamer -->
<dependency>
    <groupId>com.thoughtworks.paranamer</groupId>
    <artifactId>paranamer</artifactId>
    <version>2.8</version>
</dependency>
                                    
  </dependencies>
</project>

6. 在项目中增加scala语言支持

项目名上右键-》配置-》"Add Scala Nature"

7.在项目新建一个“Scala Object”  名为 SparkPi 新建的SparkPi.scala文件 内容参考

/spark/examples/examples/src/main/scala/org/apache/spark/examples/SparkPi.scala 文件

8. 点击运行-》Run As -》Scala Application

可以看到正常执行

接下来测试WordCount等其它examples 也可以正常执行

eclipse + Maven + scala + Spark 开发测试环境配置完毕

猜你喜欢

转载自blog.csdn.net/oLinBSoft/article/details/84592150