Programmatic scala compilation throw 'object scala in compiler mirror' error

#1

Hi,

My dependencies are

scala-library-2.11.11
scala-compiler-2.11.11
scala-reflect-2.11.11

$ java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (Zulu 8.20.0.5-macosx) (build 1.8.0_121-b15)
OpenJDK 64-Bit Server VM (Zulu 8.20.0.5-macosx) (build 25.121-b15, mixed mode)

I have the following code.

import scala.tools.nsc.MainClass

object CompileStuff extends App {

  val mainClass = new MainClass()
  mainClass.main(Array("Example.scala"))
}

It is throwing the following error.

error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /path_tofolder/zulu1.8.0_121-8.20.0.5/jre/lib/rt.jar(java/lang/Object.class)
error: scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
        at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
        at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
        at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:53)
        at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
        at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:173)
        at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:161)
        at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:161)
        at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:162)
        at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:162)
        at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1391)

I am not sure what the problem is. And am guessing there may be compatibility issue with jdk version and scala version. But according to docs, scala 2.11.11 and jdk 8 are compatible.

Anyone know what might be happening here?

Thanks

#2

How are you building/compiling this exactly?