Friday, 31 January 2014

Scala: Remote debugging in SBT's Jetty container

The following will attach your Scala source code to your webapp running in Jetty.

Configuration for remote debugging in SBT's embedded Jetty is not much different Maven's Jetty plugin. Here I used Scala 2.10, SBT 0.12 and dependency "jetty-webapp" 8.1

1. Export JVM debug parameters

$ export SBT_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n"

                   Note: Change parameters "suspend" and "address" to your own needs.

2. Start SBT (sbt) and configure your IDE to connect to the port SBT is listening on. In Eclipse, for example, would be something like this: 

"Run" > "Debug Configurations" > "Remote Java Application"

Create a new configuration and enter the following:

Connection TypeStandard (Socket Attach)

Select "Apply" and then "Debug"

3. Create breakpoints in your code and start the Jetty container: 



  1. Doesnt work for me.
    When I run container:start I'm receiving this error (I'm brazilian):

    Erro: Não foi possível localizar nem carregar a classe principal

    Error: Could not find or load the main class

    How Can I do to solve this?

  2. The main class is defined by extending App (i.e. Boot extends App). Make sure you have one of those and reference it from your SBT file: mainClass in assembly := Some("Boot")

    In Gradle it looks something like this: mainClassName = "Boot"