1、Windows安裝Scala或者Spark后,測試安裝成功與否時 cmd中出現以下問題:
1 Failed to initialize compiler: object java.lang.Object in compiler mirror not found. 2 ** Note that as of 2.8 scala does not assume use of the java classpath. 3 ** For the old behavior pass -usejavacp to scala, or if using a Settings 4 ** object programmatically, settings.usejavacp.value = true.
直接原因:這是與jdk版本沖突引起的,應該是jdk版本太高導致的。
解決方案:
如果是安裝Scala出現此情況,降低一下jdk版本,或者提高一下scala版本
如果是安裝Spark出現此情況,是不是你自己的jdk版本過高?,降低一下jdk版本
因為scala使用的是jvm,spark由scala寫的,不同版本其預寫的jdk版本不一致,,盡量選擇對應版本
eg.在windows上安裝spark2.3.4,對應1.8JDK,scala2.12.5或2.11.8都行,2.7.7版本HADOOP
下表是官網上的JDK與scala的版本兼容性表:
Version compatibility table
JDK version | Minimum Scala versions | Recommended Scala versions |
---|---|---|
17 | 2.13.6, 2.12.15 (forthcoming) | 2.13.6, 2.12.15 (forthcoming) |
16 | 2.13.5, 2.12.14 | 2.13.6, 2.12.14 |
13, 14, 15 | 2.13.2, 2.12.11 | 2.13.6, 2.12.14 |
12 | 2.13.1, 2.12.9 | 2.13.6, 2.12.14 |
11 | 2.13.0, 2.12.4, 2.11.12 | 2.13.6, 2.12.14, 2.11.12 |
8 | 2.13.0, 2.12.0, 2.11.0, 2.10.2 | 2.13.6, 2.12.14, 2.11.12, 2.10.7 |
6, 7 | 2.11.0, 2.10.0 | 2.11.12, 2.10.7 |
2、Error:scalac: Error: Error compiling the sbt component 'compiler-interface-2.11.8-55.0'
sbt.internal.inc.CompileFailed: Error compiling the sbt component 'compiler-interface-2.11.8-55.0'
原因:jdk版本-11與scala版本-2-11.8沖突
解決方案:(1)升級scala版本到12。
(2)降低jdk版本到1.8。