Tech TLDR;

  • Archive
  • Top Posts
  • GitHub
  • LinkedIn
  • Contact

Attach Remote Debugger to Jar File and Scala REPL

December 15, 2018 by admin

I was investigating a bug that would only happen in production and wanted to attach a debugger to a particular workflow. I could have run the entire application and attached remotely, via:

java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9998 path/to/my/jar/some.jar

In my case, I wanted to invoke a specific method and see what happens via Scala REPL.

Turns out it’s pretty easy to do, although not easy to find how to do it. I just had to trigger the Scala REPL command with the jar file passed into the -cp parameter. I also had to prepend remote debugger parameters that I got from InteliJ with -J

So the final command looked as follows:

scala -cp path/to/my/jar/some.jar -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9998

I also had to forward the port via ssh to my local machine, as follows:

ssh some-remote-server.com -L 9998:127.0.0.1:9998 -NCode language: CSS (css)

IntelliJ config for the remote debugger is under:

  1. Run
  2. Edit Configuration
  3. + in top left corner
  4. Select Remote
  5. Edit Name
  6. Edit Port
  7. Click OK
  8. Hit the debug (Run -> Debug) after Scala REPL or jar file are running

Happy coding!

Filed Under: Scala

Copyright © 2023 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in