33

Attach Remote Debugger to Jar File and Scala REPL

 6 years ago
source link: https://www.tuicool.com/articles/hit/fMZ7RrV
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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:

+
Remote

Happy coding!


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK