“scala.runtime in compiler mirror not found” but working when started with -Xbootclasspath/p:scala-library.jar

后端 未结 1 2003
感动是毒
感动是毒 2020-12-16 17:21

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 -Xbootclasspath/p opt

相关标签:
1条回答
  • 2020-12-16 17:54

    The easy way to configure the settings with familiar keystrokes:

      import scala.tools.nsc.Global
      import scala.tools.nsc.Settings
      def main(args: Array[String]) {
        val s = new Settings
        s processArgumentString "-usejavacp"
        val g = new Global(s)
        val r = new g.Run
      }
    

    That works for your scenario.

    Even easier:

    java -Dscala.usejavacp=true -jar ./scall.jar
    

    Bonus info, I happened to come across the enabling commit message:

    Went ahead and implemented classpaths as described in email to scala-internals on the theory that at this point I must know what I'm doing.

    ** PUBLIC SERVICE ANNOUNCEMENT **

    If your code of whatever kind stopped working with this commit (most likely the error is something like "object scala not found") you can get it working again with either of:

    passing -usejavacp on the command line

    set system property "scala.usejavacp" to "true"

    Either of these will alert scala that you want the java application classpath to be utilized by scala as well.

    0 讨论(0)
提交回复
热议问题