Intellij plugin 설치는 scala , sbt 플러그인을 설치해야 한다.
설치법은 구글에 잘 나와있으니 pass~!
샘플 프로젝트는 SBT 기반 프로젝트를 생성하면 된다.
프로젝트 생성
프로젝트 구조
build.sbt (spark 2.2.0 기반)
name := "sparkTest1" version := "1.0" scalaVersion := "2.11.8" libraryDependencies ++= { val sparkVer = "2.2.0" Seq( "org.apache.spark" %% "spark-core" % sparkVer ) }
샘플코드
import org.apache.spark.{SparkConf, SparkContext} object LineCount { def main(args: Array[String]): Unit = { val logFile = "text_file_full_path.txt" val conf = new SparkConf().setAppName("Simple Application").setMaster("local") val sc = new SparkContext(conf) val logData = sc.textFile(logFile, 2).cache() val lineCount = logData.count() println(lineCount) sc.stop() } }
삽질
아래와 같은 에러가 발생.
idea sbt java.lang.NoClassDefFoundError: org/apache/spark/SparkConf
해결은 아래의 링크에서
https://stackoverflow.com/questions/37849408/idea-sbt-java-lang-noclassdeffounderror-org-apache-spark-sparkconf
문제는 build.sbt 에서 % "provided" withSources() 가 문제였다.
libraryDependencies ++= {
val sparkVer = "2.2.0"
Seq(
"org.apache.spark" %% "spark-core" % sparkVer % "provided" withSources())
}
참고 링크
- "Setting UP Spark 2.0 environment on intellij community edition version" 으로 구글 검색, pdf 다운
- http://cyberx.tistory.com/143
- http://kysepark.blogspot.kr/2016/03/intellij-spark.html
- http://dev4u.tistory.com/entry/Spark-Intelij-SBT-scala-%EA%B0%9C%EB%B0%9C%ED%99%98%EA%B2%BD-%EC%84%A4%EC%A0%95%ED%95%B4-%EB%B3%B4%EA%B8%B0
'IT > Spark' 카테고리의 다른 글
RDD 정리 (0) | 2017.12.08 |
---|---|
Practice using the results "jar" in Spark (0) | 2017.11.28 |
Reading before learning Spark (0) | 2017.11.22 |
spark shell test (0) | 2017.11.20 |
Spark install Command Line history (0) | 2017.11.20 |