- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Dropping into Interpreter for Interactive Debugging
Wed, 2012-01-18, 21:52
Hi all,
I've been trying to find a way to drop into the interpreter
programmatically to interactively debug my code. My code will be
running through SBT, and so far I have been unable to find a working
solution. Posted is my example SBT build.sbt,
// Project settings
scalaVersion := "2.9.1"
// copy retrieved dependencies to ./lib_managed
retrieveManaged := true
// libraries
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % "2.9.1",
"org.scala-lang" % "jline" % "2.9.1"
)
// Compiler options
scalacOptions ++= Seq(
"-unchecked",
"-deprecation"
)
And my actual Main.scala program,
import scala.tools.nsc.interpreter.ILoop._
object Main extends App {
case class C(a: Int, b: Double, c: String) {
def throwAFit(): Unit = {
println("But I don't wanna!!!")
}
}
// main
override def main(args: Array[String]): Unit = {
val c = C(1, 2.0, "davis")
0.until(10).foreach {
i =>
println("i = " + i)
breakIf(i == 5)
}
}
}
Currently, I get the following (expected) error,
Failed to initialize compiler: object scala not found.
** Note that as of 2.8 scala does not assume use of the java
classpath.
** For the old behavior pass -usejavacp to scala, or if using a
Settings
** object programatically, settings.usejavacp.value = true.
However, including "-usejavacp" in scalacOptions in my build.sbt file
fails to fix the issue. Furthermore, compiling my code directly with
scalac and executing it results in the same issue found with "scala -
i" here: https://issues.scala-lang.org/browse/SI-4945
Can anyone help me get an interactive debugger running? Thanks!
Hi Daniel,
See "embeddedDefaults" in the FAQ: https://github.com/harrah/xsbt/wiki/FAQ
-jason