Reputation: 688
I'm trying to get an interactive shell into my Scala application. I'm using the following system:
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've tried several settings and class path configurations, but didn't find a working configuration. Can someone give me a hint/solution for this problem?
Upvotes: 4
Views: 590
Reputation: 2095
Have you tried to re-import all classpath with 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)
}
Upvotes: 0