Embedded Scala REPL inherits parent classpath
scala
Solution
I'm trying to do the same thing, and I just found a way my out by Googling:
lazy val urls = java.lang.Thread.currentThread.getContextClassLoader match {
case cl: java.net.URLClassLoader => cl.getURLs.toList
case _ => error("classloader is not a URLClassLoader")
}
lazy val classpath = urls map {_.toString}
The above code gets you the classpath in current context.
settings.classpath.value = classpath.distinct.mkString(java.io.File.pathSeparator)
Put that into your `settings.classpath` and you should be able to fire up dispatch or whatever library you need.
Problem
As asked in this thread on the Scala mailing list, how can I create an embedded Scala REPL that inherits the classpath of the parent program? Suppose the parent Scala program is launched using `scala -cp <classpath> ...`; can `<classpath>` be accessed as a string and used to initialize the embedded REPL? (The Java classpath, available via `System.getProperty("java.class.path")`, appears to differ from the Scala classpath.) Alternatively, perhaps the embedded Scala REPL can inherit or construct its ClassLoader from the parent process (Michael Dürig's ScalaDays 2010 talk might be relevant). Is this the recommended approach?