scala 无法初始化编译器:未找到编译器镜像中的对象 java.lang.Object
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38602889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to initialize compiler: object java.lang.Object in compiler mirror not found
提问by Kevin Meredith
On Ubuntu 16.04, I installed scala:
在 Ubuntu 16.04 上,我安装了scala:
$ls ~/Binary/scala-2.11.8
bin doc lib man
$grep -A 2 SCALA ~/.bashrc
SCALA=~/Binary/scala-2.11.8
SBT=~/Binary/sbt
export PATH=$PATH:$SCALA/bin:$SBT/bin
With openjdk8installed, scalafails when opening the REPL:
随着openjdk8安装,scala打开REPL时失败:
$javac -version
javac 1.8.0_91
$
$scala
Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 9-internal).
Type in expressions for evaluation. Or try :help.
scala>
Failed to initialize compiler: object java.lang.Object in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programmatically, settings.usejavacp.value = true.
Failed to initialize compiler: object java.lang.Object in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programmatically, settings.usejavacp.value = true.
How can I resolve it?
我该如何解决?
采纳答案by WOPR
Using the Java 8 version of OpenJDK resolved this issue for me.
使用 Java 8 版本的 OpenJDK 为我解决了这个问题。
sudo update-alternatives --config java
sudo update-alternatives --config javac
回答by Dbz
This issue appears to be with Java 9 and gets solved with Java 8.
这个问题似乎与 Java 9 相关,并在 Java 8 中得到解决。
If you have Java 8 and Java 9, and you would like to keep both, you can set your environment variable JAVA_HOMEto the Java 8 path.
如果您有 Java 8 和 Java 9,并且希望同时保留两者,则可以将环境变量JAVA_HOME设置为 Java 8 路径。
For example:
例如:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home
You will need to replace jdk1.8.0_161.jdkwith whichever version of the JDK that you have.
您将需要替换jdk1.8.0_161.jdk为您拥有的任何版本的 JDK。
You can find that version with:
您可以通过以下方式找到该版本:
ls /Library/Java/JavaVirtualMachines/
ls /Library/Java/JavaVirtualMachines/
Once you set that environment variable, you can open a new terminal and run java -versionto see if the version was set correctly.
设置该环境变量后,您可以打开一个新终端并运行java -version以查看版本设置是否正确。
EDIT:
编辑:
It may be worth noting that I have a Mac even though this is a linux question.
值得注意的是,尽管这是一个 linux 问题,但我有一台 Mac。
回答by Yash P Shah
Installing java version "1.8.0_144" resolved the issue for me. I had installed jdk 1.9 previously.
安装 java 版本“1.8.0_144”为我解决了这个问题。我之前安装了 jdk 1.9。
回答by silverberry
Java 8 is deprecated, so downgrading to is must NOT be an acceptable solution.
Java 8 已被弃用,因此降级到是不能接受的解决方案。
The correct solution is to upgrade your SBT to 0.13.17 or higher.
正确的解决方案是将您的 SBT 升级到 0.13.17 或更高版本。
回答by Styne.John.
Installing Java 8 resolved this issue.
安装 Java 8 解决了这个问题。
I downloaded java 8 and i extracted that to the following location : /usr/lib/jvm/jdk1.8.0_172
我下载了 java 8 并将其解压缩到以下位置:/usr/lib/jvm/jdk1.8.0_172
After doing this update the JAVA_HOME path to the same : /usr/lib/jvm/jdk1.8.0_172
执行此操作后,将 JAVA_HOME 路径更新为相同的:/usr/lib/jvm/jdk1.8.0_172
This will resolve the issue.
这将解决问题。
回答by Murali Bala
I ran into the same issue. Uninstall Java 9
我遇到了同样的问题。卸载 Java 9
sudo rm -fr /Library/Java/JavaVirtualMachines/jdk-9.jdk/
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
Ref: https://gist.github.com/schnell18/bcb9833f725be22f6acd01f94b486392
参考:https: //gist.github.com/schnell18/bcb9833f725be22f6acd01f94b486392
Install Java 8.
安装 Java 8。
Everything seems to good now.
现在一切似乎都很好。
Btw: this was for mac. Might be useful for you.
顺便说一句:这是针对 mac 的。可能对你有用。
回答by Anthony Awuley
Worked with this java version "1.8.0_144"
使用此 Java 版本“1.8.0_144”
Uninstall java and apache-spark
卸载 java 和 apache-spark
install java, install apache-spark
安装java,安装apache-spark
回答by user7392763
i had a zip of my jdk at the same location. Removing the zip did the trick for me.
我在同一位置有我的 jdk 的 zip。去除拉链对我来说很有效。

