alexkras.com

  • Home
  • Top Posts
  • Resume
  • Projects
  • YouTube
  • Boots to Bytes
  • About
  • Contact

Attach Remote Debugger to Jar File and Scala REPL

December 15, 2018 by Alex Kras Leave a Comment

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 -N

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

I work for Evernote and we are hiring!

Subscribe to this Blog via Email

New posts only. No other messages will be sent.

You can find me on LinkedIn, GitHub, Twitter or Facebook.

This blog is moving to techtldr.com

Leave a Reply Cancel reply

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