summaryrefslogtreecommitdiff
path: root/site/docs/1.0.1/building-with-maven.html
blob: 2d44529524ba859fc9142c30afd5c84ab5553aa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Building Spark with Maven - Spark 1.0.1 Documentation</title>
        <meta name="description" content="">

        

        <link rel="stylesheet" href="css/bootstrap.min.css">
        <style>
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
        </style>
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="css/main.css">

        <script src="js/vendor/modernizr-2.6.1-respond-1.1.0.min.js"></script>

        <link rel="stylesheet" href="css/pygments-default.css">

        
        <!-- Google analytics script -->
        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-32518208-1']);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();
        </script>
        

    </head>
    <body>
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
        <![endif]-->

        <!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->

        <div class="navbar navbar-fixed-top" id="topbar">
            <div class="navbar-inner">
                <div class="container">
                    <div class="brand"><a href="index.html">
                      <img src="img/spark-logo-hd.png" style="height:50px;"/></a><span class="version">1.0.1</span>
                    </div>
                    <ul class="nav">
                        <!--TODO(andyk): Add class="active" attribute to li some how.-->
                        <li><a href="index.html">Overview</a></li>

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Programming Guides<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="quick-start.html">Quick Start</a></li>
                                <li><a href="programming-guide.html">Spark Programming Guide</a></li>
                                <li class="divider"></li>
                                <li><a href="streaming-programming-guide.html">Spark Streaming</a></li>
                                <li><a href="sql-programming-guide.html">Spark SQL</a></li>
                                <li><a href="mllib-guide.html">MLlib (Machine Learning)</a></li>
                                <li><a href="graphx-programming-guide.html">GraphX (Graph Processing)</a></li>
                                <li><a href="bagel-programming-guide.html">Bagel (Pregel on Spark)</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">API Docs<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="api/scala/index.html#org.apache.spark.package">Scaladoc</a></li>
                                <li><a href="api/java/index.html">Javadoc</a></li>
                                <li><a href="api/python/index.html">Python API</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Deploying<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="cluster-overview.html">Overview</a></li>
                                <li><a href="submitting-applications.html">Submitting Applications</a></li>
                                <li class="divider"></li>
                                <li><a href="ec2-scripts.html">Amazon EC2</a></li>
                                <li><a href="spark-standalone.html">Standalone Mode</a></li>
                                <li><a href="running-on-mesos.html">Mesos</a></li>
                                <li><a href="running-on-yarn.html">YARN</a></li>
                            </ul>
                        </li>

                        <li class="dropdown">
                            <a href="api.html" class="dropdown-toggle" data-toggle="dropdown">More<b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="configuration.html">Configuration</a></li>
                                <li><a href="monitoring.html">Monitoring</a></li>
                                <li><a href="tuning.html">Tuning Guide</a></li>
                                <li><a href="job-scheduling.html">Job Scheduling</a></li>
                                <li><a href="security.html">Security</a></li>
                                <li><a href="hardware-provisioning.html">Hardware Provisioning</a></li>
                                <li><a href="hadoop-third-party-distributions.html">3<sup>rd</sup>-Party Hadoop Distros</a></li>
                                <li class="divider"></li>
                                <li><a href="building-with-maven.html">Building Spark with Maven</a></li>
                                <li><a href="https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark">Contributing to Spark</a></li>
                            </ul>
                        </li>
                    </ul>
                    <!--<p class="navbar-text pull-right"><span class="version-text">v1.0.1</span></p>-->
                </div>
            </div>
        </div>

        <div class="container" id="content">
          
            <h1 class="title">Building Spark with Maven</h1>
          

          <ul id="markdown-toc">
  <li><a href="#setting-up-mavens-memory-usage">Setting up Maven&#8217;s Memory Usage</a></li>
  <li><a href="#specifying-the-hadoop-version">Specifying the Hadoop Version</a></li>
  <li><a href="#spark-tests-in-maven">Spark Tests in Maven</a></li>
  <li><a href="#continuous-compilation">Continuous Compilation</a></li>
  <li><a href="#using-with-intellij-idea">Using With IntelliJ IDEA</a></li>
  <li><a href="#building-spark-debian-packages">Building Spark Debian Packages</a></li>
  <li><a href="#running-java-8-test-suites">Running Java 8 Test Suites</a></li>
  <li><a href="#building-for-pyspark-on-yarn">Building for PySpark on YARN</a></li>
  <li><a href="#packaging-without-hadoop-dependencies-for-yarn">Packaging without Hadoop Dependencies for YARN</a></li>
</ul>

<p>Building Spark using Maven requires Maven 3.0.4 or newer and Java 6+.</p>

<h1 id="setting-up-mavens-memory-usage">Setting up Maven&#8217;s Memory Usage</h1>

<p>You&#8217;ll need to configure Maven to use more memory than usual by setting <code>MAVEN_OPTS</code>. We recommend the following settings:</p>

<div class="highlight"><pre><code class="bash"><span class="nb">export </span><span class="nv">MAVEN_OPTS</span><span class="o">=</span><span class="s2">&quot;-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m&quot;</span>
</code></pre></div>

<p>If you don&#8217;t run this, you may see errors like the following:</p>

<pre><code>[INFO] Compiling 203 Scala sources and 9 Java sources to /Users/me/Development/spark/core/target/scala-2.10/classes...
[ERROR] PermGen space -&gt; [Help 1]

[INFO] Compiling 203 Scala sources and 9 Java sources to /Users/me/Development/spark/core/target/scala-2.10/classes...
[ERROR] Java heap space -&gt; [Help 1]
</code></pre>

<p>You can fix this by setting the <code>MAVEN_OPTS</code> variable as discussed before.</p>

<p><strong>Note:</strong> <em>For Java 8 and above this step is not required.</em></p>

<h1 id="specifying-the-hadoop-version">Specifying the Hadoop Version</h1>

<p>Because HDFS is not protocol-compatible across versions, if you want to read from HDFS, you&#8217;ll need to build Spark against the specific HDFS version in your environment. You can do this through the &#8220;hadoop.version&#8221; property. If unset, Spark will build against Hadoop 1.0.4 by default. Note that certain build profiles are required for particular Hadoop versions:</p>

<table class="table">
  <thead>
    <tr><th>Hadoop version</th><th>Profile required</th></tr>
  </thead>
  <tbody>
    <tr><td>0.23.x</td><td>hadoop-0.23</td></tr>
    <tr><td>1.x to 2.1.x</td><td>(none)</td></tr>
    <tr><td>2.2.x</td><td>hadoop-2.2</td></tr>
    <tr><td>2.3.x</td><td>hadoop-2.3</td></tr>
    <tr><td>2.4.x</td><td>hadoop-2.4</td></tr>
  </tbody>
</table>

<p>For Apache Hadoop versions 1.x, Cloudera CDH &#8220;mr1&#8221; distributions, and other Hadoop versions without YARN, use:</p>

<div class="highlight"><pre><code class="bash"><span class="c"># Apache Hadoop 1.2.1</span>
mvn -Dhadoop.version<span class="o">=</span>1.2.1 -DskipTests clean package

<span class="c"># Cloudera CDH 4.2.0 with MapReduce v1</span>
mvn -Dhadoop.version<span class="o">=</span>2.0.0-mr1-cdh4.2.0 -DskipTests clean package

<span class="c"># Apache Hadoop 0.23.x</span>
mvn -Phadoop-0.23 -Dhadoop.version<span class="o">=</span>0.23.7 -DskipTests clean package
</code></pre></div>

<p>For Apache Hadoop 2.x, 0.23.x, Cloudera CDH, and other Hadoop versions with YARN, you can enable the &#8220;yarn-alpha&#8221; or &#8220;yarn&#8221; profile and optionally set the &#8220;yarn.version&#8221; property if it is different from &#8220;hadoop.version&#8221;. The additional build profile required depends on the YARN version:</p>

<table class="table">
  <thead>
    <tr><th>YARN version</th><th>Profile required</th></tr>
  </thead>
  <tbody>
    <tr><td>0.23.x to 2.1.x</td><td>yarn-alpha</td></tr>
    <tr><td>2.2.x and later</td><td>yarn</td></tr>
  </tbody>
</table>

<p>Examples:</p>

<div class="highlight"><pre><code class="bash"><span class="c"># Apache Hadoop 2.0.5-alpha</span>
mvn -Pyarn-alpha -Dhadoop.version<span class="o">=</span>2.0.5-alpha -DskipTests clean package

<span class="c"># Cloudera CDH 4.2.0</span>
mvn -Pyarn-alpha -Dhadoop.version<span class="o">=</span>2.0.0-cdh4.2.0 -DskipTests clean package

<span class="c"># Apache Hadoop 0.23.x</span>
mvn -Pyarn-alpha -Phadoop-0.23 -Dhadoop.version<span class="o">=</span>0.23.7 -DskipTests clean package

<span class="c"># Apache Hadoop 2.2.X</span>
mvn -Pyarn -Phadoop-2.2 -Dhadoop.version<span class="o">=</span>2.2.0 -DskipTests clean package

<span class="c"># Apache Hadoop 2.3.X</span>
mvn -Pyarn -Phadoop-2.3 -Dhadoop.version<span class="o">=</span>2.3.0 -DskipTests clean package

<span class="c"># Apache Hadoop 2.4.X</span>
mvn -Pyarn -Phadoop-2.4 -Dhadoop.version<span class="o">=</span>2.4.0 -DskipTests clean package

<span class="c"># Different versions of HDFS and YARN.</span>
mvn -Pyarn-alpha -Phadoop-2.3 -Dhadoop.version<span class="o">=</span>2.3.0 -Dyarn.version<span class="o">=</span>0.23.7 -DskipTests clean package
</code></pre></div>

<h1 id="spark-tests-in-maven">Spark Tests in Maven</h1>

<p>Tests are run by default via the <a href="http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin">ScalaTest Maven plugin</a>. Some of the require Spark to be packaged first, so always run <code>mvn package</code> with <code>-DskipTests</code> the first time. You can then run the tests with <code>mvn -Dhadoop.version=... test</code>.</p>

<p>The ScalaTest plugin also supports running only a specific test suite as follows:</p>

<pre><code>mvn -Dhadoop.version=... -DwildcardSuites=org.apache.spark.repl.ReplSuite test
</code></pre>

<h1 id="continuous-compilation">Continuous Compilation</h1>

<p>We use the scala-maven-plugin which supports incremental and continuous compilation. E.g.</p>

<pre><code>mvn scala:cc
</code></pre>

<p>should run continuous compilation (i.e. wait for changes). However, this has not been tested extensively.</p>

<h1 id="using-with-intellij-idea">Using With IntelliJ IDEA</h1>

<p>This setup works fine in IntelliJ IDEA 11.1.4. After opening the project via the pom.xml file in the project root folder, you only need to activate either the hadoop1 or hadoop2 profile in the &#8220;Maven Properties&#8221; popout. We have not tried Eclipse/Scala IDE with this.</p>

<h1 id="building-spark-debian-packages">Building Spark Debian Packages</h1>

<p>The Maven build includes support for building a Debian package containing the assembly &#8216;fat-jar&#8217;, PySpark, and the necessary scripts and configuration files. This can be created by specifying the following:</p>

<pre><code>mvn -Pdeb -DskipTests clean package
</code></pre>

<p>The debian package can then be found under assembly/target. We added the short commit hash to the file name so that we can distinguish individual packages built for SNAPSHOT versions.</p>

<h1 id="running-java-8-test-suites">Running Java 8 Test Suites</h1>

<p>Running only Java 8 tests and nothing else.</p>

<pre><code>mvn install -DskipTests -Pjava8-tests
</code></pre>

<p>Java 8 tests are run when <code>-Pjava8-tests</code> profile is enabled, they will run in spite of <code>-DskipTests</code>. 
For these tests to run your system must have a JDK 8 installation. 
If you have JDK 8 installed but it is not the system default, you can set JAVA_HOME to point to JDK 8 before running the tests.</p>

<h1 id="building-for-pyspark-on-yarn">Building for PySpark on YARN</h1>

<p>PySpark on YARN is only supported if the jar is built with Maven. Further, there is a known problem
with building this assembly jar on Red Hat based operating systems (see <a href="https://issues.apache.org/jira/browse/SPARK-1753">SPARK-1753</a>). If you wish to
run PySpark on a YARN cluster with Red Hat installed, we recommend that you build the jar elsewhere,
then ship it over to the cluster. We are investigating the exact cause for this.</p>

<h1 id="packaging-without-hadoop-dependencies-for-yarn">Packaging without Hadoop Dependencies for YARN</h1>

<p>The assembly jar produced by <code>mvn package</code> will, by default, include all of Spark&#8217;s dependencies, including Hadoop and some of its ecosystem projects. On YARN deployments, this causes multiple versions of these to appear on executor classpaths: the version packaged in the Spark assembly and the version on each node, included with yarn.application.classpath.  The <code>hadoop-provided</code> profile builds the assembly without including Hadoop-ecosystem projects, like ZooKeeper and Hadoop itself. </p>



        </div> <!-- /container -->

        <script src="js/vendor/jquery-1.8.0.min.js"></script>
        <script src="js/vendor/bootstrap.min.js"></script>
        <script src="js/main.js"></script>

        <!-- MathJax Section -->
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({
                TeX: { equationNumbers: { autoNumber: "AMS" } }
            });
        </script>
        <script>
            // Note that we load MathJax this way to work with local file (file://), HTTP and HTTPS.
            // We could use "//cdn.mathjax...", but that won't support "file://".
            (function(d, script) {
                script = d.createElement('script');
                script.type = 'text/javascript';
                script.async = true;
                script.onload = function(){
                    MathJax.Hub.Config({
                        tex2jax: {
                            inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ],
                            displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], 
                            processEscapes: true,
                            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
                        }
                    });
                };
                script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') +
                    'cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
                d.getElementsByTagName('head')[0].appendChild(script);
            }(document));
        </script>
    </body>
</html>