最近突然想起来看一下spark源码,下载下spark源码之后debug突然发现不能运行报错如下
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.spark.package$.<init>(package.scala:91)
at org.apache.spark.package$.<clinit>(package.scala)
at org.apache.spark.SparkContext$$anonfun$3.apply(SparkContext.scala:184)
at org.apache.spark.SparkContext$$anonfun$3.apply(SparkContext.scala:184)
at org.apache.spark.internal.Logging$class.logInfo(Logging.scala:54)
at org.apache.spark.SparkContext.logInfo(SparkContext.scala:73)
at org.apache.spark.SparkContext.<init>(SparkContext.scala:184)
at org.apache.sparktest.mytest$.main(mytest.scala:15)
at org.apache.sparktest.mytest.main(mytest.scala)
Caused by: org.apache.spark.SparkException: Error while locating file spark-version-info.properties
at org.apache.spark.package$SparkBuildInfo$.liftedTree1$1(package.scala:75)
at org.apache.spark.package$SparkBuildInfo$.<init>(package.scala:61)
at org.apache.spark.package$SparkBuildInfo$.<clinit>(package.scala)
... 9 more
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at org.apache.spark.package$SparkBuildInfo$.liftedTree1$1(package.scala:64)
... 11 more
请注意看下面的几行Caused by:后面的异常栈,发现是读取不到文件信息。那么它读取的是哪一个文件呢?
请看下图
当然了如果环境允许你可以自己编译产生这个文件,如果不允许你也可以下载spark编译之后的文件,找到spark-core包里面的这个properties文件。然后把它放入工程文件里面。
那么问题来了,挖掘机技术哪家强?
当然是看spark栈信息,点击异常栈进入错误的代码地方可以看到源码提示如下
val resourceStream = Thread.currentThread().getContextClassLoader.
getResourceAsStream(".idea/spark-version-info.properties")
接下来怎么做就不用我多说了吧