REPL using IMain, Akka and sbt: get import work

I am trying to get an interactive shell in my Scala application. I am using the following system:

  • Scala 2.10.0
  • sbt 0.12.2
  • Akka 2.1.0
  • sbt-lwjgl-plugin 3.1.4

and the following non-working code:

import akka.actor.Actor import scala.tools.nsc.Settings import scala.tools.nsc.interpreter.IMain class TestActor extends Actor { def receive => { case _ => { val settings = new Settings settings.usejavacp.value = true settings embeddedDefaults ActorSystem.getClass.getClassLoader val repl = new IMain(settings) repl.interpret("import java._") // working repl.interpret("import scala._") // working repl.interpret("import akka._") // not working repl.interpret("import other.java.class.Bar") // not working } } } 

Sbt is set to fork := true . I tried several settings and class path configurations, but did not find a working configuration. Can someone give me a hint / solution to this problem?

+4
source share
1 answer

Have you tried to reimport all the way to classes with an absolute path?

 val settings = new Settings settings.usejavacp.value = true val classLoader = Thread.currentThread.getContextClassLoader classLoader.asInstanceOf[URLClassLoader].getURLs.map(url => new File(url.toURI).getAbsolutePath).foreach { jarPath => println(s"adding into Scala SDK classpath : ${jarPath}") settings.bootclasspath.append(jarPath) settings.classpath.append(jarPath) } 
0
source

All Articles