javadebuggingjrubyjruby-java-interop

Debugging between JRuby and Java


I have a large Java project that uses some Ruby scripts (primarily because of Ruby's support for "yield"). The Ruby code calls Java code which calls more Ruby code. It's very interleaved, but everything is driven from Java.

I'm using embedded jruby-standalone and building a jar-with-dependencies (via maven). I'm using a maven plugin to run jrubyc and generate .java files which maven compiles for me.

When I run the jar-with-dependencies, I can attach my debugger to the Java process with no problems, but I'd really love to be able to debug the Ruby code. Is there a solution for this?

I'm not launching any kind of jruby executable to which I could attach arguments. It's embedded in the jar and invoked via java -jar.


Solution

  • You could use the gem pry-remote.

    Unlike pry, it does not require the process to be launched from a terminal (or a terminal emulator if you're on Windows).

    It's not really a debugger per se, but if you add binding.remote_pry in your code where you wish to observe and react within that context (you could for example catch an exception), this would put pry in waiting mode for a remote connection, and from another terminal you should be able to connect to this process and debug it.

    2 minutes hands-on tutorial is available here.

    Drawbacks:

    I use this in pre-deployment environments when developing web apps with jruby, h2 and jetty server.

    Good luck!