title: "scala.runtime in compiler mirror not found" but working when started with -Xbootclasspath/p:scala-library.jar
body: <p>I'm trying to run a Scala application packed as JAR (including dependencies) but this fails until the Scala library is added by using the <code>-Xbootclasspath/p</code> option.</p>
  
  <p>Failing invocation:</p>
  
  <pre><code>java -jar /path/to/target/scala-2.10/application-assembly-1.0.jar
  </code></pre>
  
  <p>After the application did some of its intended output, the console shows:</p>
  
  <blockquote>
    <p>Exception in thread "main"
    scala.reflect.internal.MissingRequirementError: object scala.runtime
    in compiler mirror not found.
            at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:16)
            at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:17)
            at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
            at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
            at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
            at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:172)
            at scala.reflect.internal.Mirrors$RootsBase.getRequiredPackage(Mirrors.scala:175)
            at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage$lzycompute(Definitions.scala:181)
            at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackage(Definitions.scala:181)
            at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackageClass$lzycompute(Definitions.scala:182)
            at scala.reflect.internal.Definitions$DefinitionsClass.RuntimePackageClass(Definitions.scala:182)
            at scala.reflect.internal.Definitions$DefinitionsClass.AnnotationDefaultAttr$lzycompute(Definitions.scala:1015)
            at scala.reflect.internal.Definitions$DefinitionsClass.AnnotationDefaultAttr(Definitions.scala:1014)
            at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses$lzycompute(Definitions.scala:1144)
            at scala.reflect.internal.Definitions$DefinitionsClass.syntheticCoreClasses(Definitions.scala:1143)
            at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode$lzycompute(Definitions.scala:1187)
            at scala.reflect.internal.Definitions$DefinitionsClass.symbolsNotPresentInBytecode(Definitions.scala:1187)
            at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1252)
            at scala.tools.nsc.Global$Run.(Global.scala:1290)
            at extract.ScalaExtractor$Compiler$2$.(ScalaExtractor.scala:24)</p>
  </blockquote>
  
  <p>Working invocation:</p>
  
  <pre><code>java -Xbootclasspath/p:/path/to/home/.sbt/boot/scala-2.10.2/lib/scala-library.jar -jar /path/to/target/scala-2.10/application-assembly-1.0.jar
  </code></pre>
  
  <p>The strange thing about it is that the <code>application-assembly-1.0.jar</code> was built so that it includes all dependencies including the Scala library. When one extracts the JAR file it can be verified that the class files in the <code>scala.runtime</code> package have been included.</p>
  
  <p><strong>Creation of the JAR file</strong></p>
  
  <p><code>addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.1")</code> was added to <code>project/plugins.sbt</code> and the <code>assembly</code> target was invoked. A JAR file of about 25MB results.</p>
  
  <p>Building the JAR with proguard shows the same runtime behavior as seen with assembly's JAR file.</p>
  
  <p><strong>Application code that triggers the MissingRequirementError</strong></p>
  
  <p>Some application code works fine and the previously described exception is triggered as soon as the <code>new Run</code> from the following fragment executes.</p>
  
  <pre><code>import scala.reflect.internal.util.BatchSourceFile
  import scala.reflect.io.AbstractFile
  import scala.reflect.io.Path.jfile2path
  import scala.tools.nsc.Global
  import scala.tools.nsc.Settings
  …
  import scala.tools.nsc._
  object Compiler extends Global(new Settings()) {
    new Run // This is line 24 from the stack trace!
  
    def parse(path: File) = {
      val code = AbstractFile.getFile(path)
      val bfs = new BatchSourceFile(code, code.toCharArray)
      val parser = new syntaxAnalyzer.UnitParser(new CompilationUnit(bfs))
      parser.smartParse()
    }
  }
  val ast = Compiler.parse(file)
  </code></pre>
  
  <p>Among others, <code>scala-library</code>, <code>scala-compiler</code> and <code>scala-reflect</code> are defined as dependencies in <code>build.sbt</code>.</p>
  
  <p><strong>For the curios / background information</strong></p>
  
  <p>The aim of the application is to aid in localization of Java and Scala programs. The task of the code fragment above is to get an AST from a Scala file in order to find method calls in there.</p>
  
  <p><strong>The questions</strong></p>
  
  <ul>
  <li>Given the Scala library is included in the JAR file, why is necessary to call the JAR using <code>-Xbootclasspath/p:scala-library.jar</code>?</li>
  <li>Why do other parts of the application run just fine even though <code>scala.runtime</code> is reported as missing later?</li>
  </ul>