美文网首页
spark源码学习(2)--编译源码+踩坑记录

spark源码学习(2)--编译源码+踩坑记录

作者: 小北觅 | 来源:发表于2019-12-06 15:18 被阅读0次

写个博客记录一下自己编译spark源码和运行spark源码中examples例子的过程。我跑的程序是JavaSparkPi这个例子,求π的值。结果如下:

下面是整个实验过程:

1.首先用git把源码clone下来,我用的是2.4.4版本,在windows7环境下编译。

2.直接用官方文档中的方法,在git中进入spark源码目录,执行下面的命令。

./build/mvn -DskipTests clean package

3.编译源码花了40多分钟吧,没有出错。

4.用IDEA导入编译后的源码。

5.准备运行spark-examples下面的例子。直接run,发现会出现各种类找不到,未定义什么的。此时按如下方法做。

  • 首先修改spark-examples的pom.xml文件,用ctrl+r把 provided全部替换为compile

  • 然后在spark-examples的pom.xml文件中添加如下代码

    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <scope>compile</scope>
    </dependency>
  • 接着还需要添加jetty的依赖包
<dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-util</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-security</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-http</artifactId>
      <scope>compile</scope>
    </dependency>
  • 最后在运行前,还要再run configuration中添加VM options
    -Dspark.master=local

接下来就可以直接run了。

相关文章

网友评论

      本文标题:spark源码学习(2)--编译源码+踩坑记录

      本文链接:https://www.haomeiwen.com/subject/dwcegctx.html