scala.tools.nsc.IMain within Play 2.1

前端 未结 2 571
萌比男神i
萌比男神i 2020-12-16 03:43

I googled a lot and am totally stuck now. I know, that there are similar questions but please read to the end. I have tried all proposed solutions and none did work.

相关标签:
2条回答
  • 2020-12-16 04:15

    I wonder if the reflect jar is missing. Try adding this too in appDependencies.

    "org.scala-lang" % "scala-reflect" % "2.10.0"
    
    0 讨论(0)
  • 2020-12-16 04:18

    The problem here is that sbt doesnt add scala-library to the class path. The following workaround works. First create a folder lib in the top project directory(the parent of app,conf etc) and copy there the scala-library.jar

    Then you can use the following code to host an interpreter :

          val settings = new Settings
          settings.bootclasspath.value +=scala.tools.util.PathResolver.Environment.javaBootClassPath + File.pathSeparator + "lib/scala-library.jar"
          val in = new IMain(settings){
                override protected def parentClassLoader = settings.getClass.getClassLoader()
          }
         val res = in.interpret("val x = 1")
    

    The above creates the bootclasspath by adding to the java class the scala library. It's not a problem with play framework it comes from the sbt. The same problem occures for any scala project when it runs with sbt. Tested with a simple project. When it runs from eclipse its works fine.

    EDIT: Link to sample project demonstrating the above.`

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