Installing SBT and compiling Scala programs in Linux __linux

Source: Internet
Author: User
Tags mkdir file permissions
SBT Introduction
SBT is a code compilation tool, is the Scala world mvn, can compile Scala,java, etc., need java1.6 above.

SBT Project Environment Establishment
SBT compilation requires a fixed directory format, and requires networking, SBT will download the dependent jar package to the user's home. Ivy2 below, the directory structure is as follows:
|--build.sbt
|--lib
|--project
|--src
| |--main
|    | |--scala
| |--test
| |--scala
|--sbt
|--target Copy code above to create a directory as follows:
Mkdir-p ~/spark_wordcount/lib
Mkdir-p ~/spark_wordcount/project
Mkdir-p ~/spark_wordcount/src/main/scala
Mkdir-p ~/spark_wordcount/src/test/scala
Mkdir-p ~/spark_wordcount/target Copy Code


1, download SBT Universal Platform Compression package: Sbt-0.13.5.tgz http://www.scala-sbt.org/download.html 2, build directory, extract files to the established directory $ sudo mkdir/usr/local/sbt$ $ sudo tar-zxvf sbt-0.13.5.tgz-c/usr/local 3, set up a boot SBT script file $ cd/usr/local/sbt/$ vim SBT/* Add SBT to the sbt_opts= text file-xms5 12m-xmx1536m-xss1m-xx:+cmsclassunloadingenabled-xx:maxpermsize=256m "Java $SBT _opts-jar/usr/local/sbt/bin/ Sbt-launch.jar "$@"
4, modify SBT file permissions $ chmod u+x SBT
5, configure the PATH environment variable, to ensure that the console can use the SBT command $ vim ~/.BASHRC/* At the end of the file add the following code, save exit/export path=/opt/scala/sbt/: $PATH
6./* Make the configuration file effective immediately/$ source ~/.BASHRC 7, test SBT whether the installation is successful/* First execution, will download some packages, and then normal use, to ensure that the network, installation after the successful display of the following * * * $ SBT sbt-version [INFO] Set current project to SBT (in Build file:/opt/scala/sbt/) [INFO] 0.13.5
8. Create Scala file import Org.apache.spark.SparkContext under project_home/src/main/scala/
Import Org.apache.spark.sparkcontext._
Import org.apache.spark.SparkConf

Object Simpleapp
{
def main (args:array[string])
{
Val logFile = "/usr/local/spark-1.5.2/readme.md"
Val conf = new sparkconf (). Setappname ("Simple Application")
Val sc = new Sparkcontext (conf)
Val logdata = Sc.textfile (LogFile, 2). Cache ()
Val numas = logdata.filter (line => line.contains ("a")). Count ()
Val numbs = logdata.filter (line => line.contains ("B")). Count ()
println ("Lines with a:%s, Lines with B:%s". Format (Numas, numbs))
}
}

9, under project_home/edit SIMPLE.SBT Name: = "Simple Project"
Version: = "1.0"
Scalaversion: = "2.10.4"
Librarydependencies + + "Org.apache.spark"% "Spark-core"% "1.0.2"
resolvers + = "Akka Repository" at "http://repo.akka.io/releases/"
10, compile package in Project_home directory run: SBT package
11, submitted to run Spark_home/bin/spark-submit--class "Simpleapp"--master Local[4]/project_home/target/scala-2.10/ Simple-project_2.10-1.0.jar


Related Article

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.