本地模式問題系列:java
問題一:會報以下不少NoClassDefFoundError的錯誤,緣由缺乏相關依賴包apache
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream at org.apache.spark.SparkConf.loadFromSystemProperties(SparkConf.scala:76) at org.apache.spark.SparkConf.<init>(SparkConf.scala:71) at org.apache.spark.SparkConf.<init>(SparkConf.scala:58) at com.hadoop.sparkPi$.main(sparkPi.scala:9) at com.hadoop.sparkPi.main(sparkPi.scala) Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.fs.FSDataInputStream at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 5 more
解決辦法:下載相關缺乏的依賴包,並在idea工程界面加入依賴包,路徑爲:file -- project structure -- libraries 中,點擊左上角「+」符號添加依賴包的路徑多線程
問題二:Spark是很是依賴內存的計算框架,在虛擬環境下使用local模式時,其實是使用多線程的形式模擬集羣進行計算,於是對於計算機的內存有必定要求,這是典型的由於計算機內存不足而拋出的異常。框架
Exception in thread "main" java.lang.IllegalArgumentException: System memory 425197568 must be at least 471859200.
Please increase heap size using the --driver-memory option or spark.driver.memory in Spark configuration.
解決辦法:修改代碼或者設置-Xms256m -Xmx1024mide
val conf = new SparkConf().setMaster("local").setAppName("sparkPi") //修改以前
val conf = new SparkConf().setMaster("local").setAppName("sparkPi").set("spark.testing.memory","2147480000") //修改以後
或oop