15

I am trying out the Scala web framework Scalatra. According to the docs here, the steps to enable IntelliJ debugging are:

  1. Add the usual JDK options for remote debugging: "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
  2. Create a "Remote" run configuration in Intellij
  3. Start up sbt, run jetty:start, and then start the remote debugger

When I do this, SBT prints out:

Listening for transport dt_socket at address: 5005

And IntelliJ prints:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'

However, breakpoints do not seem to be working. When I hit the following endpoint, with a breakpoint at the *:

class AppServlet extends AppStack {
  get("/break-test") {
*   val response = "DONE"
    response
  }
}

The code does not stop at that line, but continues so I get the response DONE back.

I am using Java 1.8.0_111, Scala 2.12, and SBT 0.13.15.

Joaquim d'Souza
  • 1,416
  • 2
  • 14
  • 25
  • I solved this by downloading the maven sources.. https://stackoverflow.com/questions/24550026/intellij-debugger-connects-but-doesnt-notice-when-code-runs-into-breakpoints/71231272#71231272 – Litchy Feb 23 '22 at 06:02

4 Answers4

6

This is what I use for remote debugging:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,addres‌​s=5005.

The value you use above in your answer, -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005, is used in the For JDK 1.4.x field.

4

Ah finally, After big struggle ! I found it for me !

I needed to disable forking in build.sbt

 fork in Test := false,

It makes total sense, as it's only the first JVM who would get to be attach to the IDE.

I hope it help someone !

tdebroc
  • 1,436
  • 13
  • 28
0

When you start SBT with -jvm-debug you are attaching the debugger to that SBT process, jetty:start will fork and run jetty in a new process. To be able to debug your app, you must set the var debugPort in build.sbt (.settings(debugPort in Jetty := 5005)) or insider SBT repl (set debugPort in Jetty := 5005) and then start jetty by using jetty:debug (I'm assuming you are using xsbt-web-plugin).

  • Ah OK, I saw somewhere else that jetty runs on the same JVM as SBT but will give this a go – Joaquim d'Souza May 30 '17 at 10:19
  • I had to use xsbt-web-plugin 3.0 for this to work, this is the code in plugin.sbt: `addSbtPlugin("com.earldouglas" %% "xsbt-web-plugin" % "3.0.0")` – brunovianarezende May 30 '17 at 10:41
  • This made a lot of sense, but did not work. I have: `addSbtPlugin("com.earldouglas" %% "xsbt-web-plugin" % "3.0.1")` And then `> set debugPort in Jetty := 5005` `> jetty:debug` Which prints out: `> Listening for transport dt_socket at address: 5005` And I run Debug from IntelliJ to get: `Connected to the target VM, address: 'localhost:5005', transport: 'socket'` But still no luck with the breakpoints :-( – Joaquim d'Souza May 30 '17 at 15:45
  • OK so my IntelliJ is out of date by ~1 year so let me update this! – Joaquim d'Souza May 30 '17 at 15:57
  • also, this is what I use in intellij for remote debugging: `-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005`. What you show above is used in the `For JDK 1.4.x ` – brunovianarezende May 30 '17 at 16:07
  • That worked! Can you add that as an answer so I can accept it? I didn't need to use `xsbt-web-plugin` or `set debugPort in Jetty := 5005` – Joaquim d'Souza May 31 '17 at 10:20
  • but, did you need to use jetty:debug? – brunovianarezende May 31 '17 at 10:24
0

In the Scalatra docs, step 1 says to update the javaOptions in the build.scala file. Instead, updating the build.sbt file fixed the issue for me. After updating the correct file, the rest of the steps in the docs worked perfectly.

build.sbt

val ScalatraVersion = "2.7.1"

ThisBuild / scalaVersion := "2.13.4"
ThisBuild / organization := "com.example"

lazy val hello = (project in file("."))
  .settings(
    name := "My Scalatra Web App",
    version := "0.1.0-SNAPSHOT",
    libraryDependencies ++= Seq(
      "org.scalatra" %% "scalatra" % ScalatraVersion,
      "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
      "ch.qos.logback" % "logback-classic" % "1.2.3" % "runtime",
      "org.eclipse.jetty" % "jetty-webapp" % "9.4.35.v20201120" % "container",
      "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
    ),
    javaOptions ++= Seq(
      "-Xdebug",
      "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
    ),
  )

enablePlugins(SbtTwirl)
enablePlugins(JettyPlugin)