Using idea to develop spark submit remote cluster execution

Source: Internet
Author: User

Development environment Operating system: Windows Development tools: IntelliJ idea 14.1.1 need to install Scala plugin compilation environment: JDK 1.7 Scala 2.10.4 using idea to develop SPARK application 1: New Scala project:

2: Choose the Scala version, need the Scala version of Spark corresponding to click on the Scala SDK's Create button, pop up the following dialog box, select the Red box
3: Add spark jar as library I directly copy all the jars inside the Spark installation directory under Lib as library.4: write the Spark app
  
 
  1. import scala.math.random
  2. import org.apache.spark._
  3. /** Computes an approximation to pi */
  4. object SparkPi {
  5. def main(args: Array[String]) {
  6. val conf = new sparkconf (). setappname ( "Spark Pi" setmaster ( "spark://192.168.1.88:7077"
  7. set("spark.driver.host","192.168.1.129").setJars(List("D:\\IdeaProjects\\scalalearn\\out\\artifacts\\scalalearn\\scalalearn.jar"))
  8. val spark = new SparkContext(conf)
  9. val Slices = if ( args length > 0 ) args Span class= "pun" > ( 0 toint else 2
  10. val n = 100000 * slices
  11. val count = spark.parallelize(1 to n, slices).map { i =>
  12. val x = random * 2 - 1
  13. val y = random * 2 - 1
  14. /span>if ( x * x + y * y < 1 ) 1 else 0
  15. }.reduce(_ + _)
  16. println("Pi is roughly " + 4.0 * count / n)
  17. spark.stop()
  18. }
  19. }
Submitting an app to a remote spark cluster there is a segment in the above codeSetjars(List("D:\\ideaprojects\\scalalearn\\out\\artifacts\\scalalearn\\scalalearn.jar"))here is the absolute path to the jar package that is currently being compiled by the project. Click File->project Structure, pop up the following dialog box to operate




Okay, now it's OK.


From for notes (Wiz)

Using idea to develop spark submit remote cluster execution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.