Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to initialize compiler: object java.lang.Object in compiler mirror not found

Tags:

scala

ubuntu

On Ubuntu 16.04, I installed 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 openjdk8 installed, scala fails when opening the 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?

like image 444
Kevin Meredith Avatar asked Jul 27 '16 02:07

Kevin Meredith


4 Answers

Using the Java 8 version of OpenJDK resolved this issue for me.

sudo update-alternatives --config java
sudo update-alternatives --config javac
like image 118
WOPR Avatar answered Nov 05 '22 17:11

WOPR


Java 8 is deprecated, so downgrading to is must NOT be an acceptable solution.

The correct solution is to upgrade your SBT to 0.13.17 or higher.

like image 37
silverberry Avatar answered Nov 05 '22 17:11

silverberry


This issue appears to be with Java 9 and gets solved with Java 8.

If you have Java 8 and Java 9, and you would like to keep both, you can set your environment variable JAVA_HOME to the Java 8 path.

For example:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

You will need to replace jdk1.8.0_161.jdk with whichever version of the JDK that you have.

You can find that version with:

ls /Library/Java/JavaVirtualMachines/

Once you set that environment variable, you can open a new terminal and run java -version to see if the version was set correctly.

EDIT:

It may be worth noting that I have a Mac even though this is a linux question.

like image 10
Dbz Avatar answered Nov 05 '22 18:11

Dbz


Installing java version "1.8.0_144" resolved the issue for me. I had installed jdk 1.9 previously.

like image 6
Yash P Shah Avatar answered Nov 05 '22 18:11

Yash P Shah