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
Code language: CSS (css)
IntelliJ config for the remote debugger is under:
- Run
- Edit Configuration
+
in top left corner- Select
Remote
- Edit Name
- Edit Port
- Click OK
- Hit the debug (Run -> Debug) after Scala REPL or jar file are running
Happy coding!