Debug Java and Ruby in same application. Follow
Has anybody been able to figure out if there is a way to debug both Java code and Ruby code in the same application? Are there any tricks for making this work with IntelliJ and the Ruby plug-in.
In Eclipse, for example, you can debug the application as Java and then, at the same time, open a remote Ruby debug port and connect to that with a second debug sessions. So you can't step debug across language boundaries, but you can put breakpoints in both types of code and step through in parallel.
Please sign in to leave a comment.
Actually you can do this using Ruby plugin for IntelliJ IDEA. Create Java run configuration and add this line to VM options:
In this case you'll be able to add breakpoints in Ruby code and stop on them.
I'm still new to IntelliJ so I have a newbie question. I'm trying to createa Java run configuration that will launch org/jruby/Main from jruby.jar directly so I can do what you're recommending. But it seems that I am being forced to do this in the context of an IntelliJ Module that contains jruby.jar so that it will show up on the classpath (as opposed to just putting the jruby.jar on the classpath via VM args command line).
Looking at the Application run configuration, if I select "no module" from the dropdown under "Use classpath and JDK of module" it shows an error saying "Module not specified". If I select the Module representing my JRuby on Rails application, it shows an error saying "class org/jruby/Main not found in module", which makes sense because jruby.jar is not an explicit part of my Rails module dependencies.
I'm guessing that to get around this I need to create an additional new Module in my Project representing the JRuby runtime and specify that in my run configuration in order to get jruby.jar onto the classpath.
But is there any other way to do this? Can I somehow just tell the Java run config explicitly which classpath to use?
The correct way to do is is to create Java module with JRuby on Rails facet enabled for it. Unfortunally we don't have enough documentation for this, but we are working on it now.
Here you can learn more about facets in IntelliJ IDEA http://www.jetbrains.com/idea/webhelp/adding-and-removing-facets-2.html
Yes, that's what I had but it didn't work. Adding the facet automtically created a global library called the "jruby facet library" but the "Classes" from that library only has paths containing ruby code, not the jruby.jar runtime itself. Here are the paths the facet library has for me:
The jruby.jar that needs to be on the classpath in order to get a Java config to run a JRuby app lives in C:\jruby-1.5.1\lib so that should probably be in there also as a JAR directory.
What I ended up doing is to create a new global library called "jruby jars" that contains just C:\jruby-1.5.1\lib as a JAR directory. If I make my JRuby on Rails module dependent on that and then set my Java run config to use that module it seems to solve the issue.
But I have one more question for you. You said that if I add -Dforce.jruby.jit=true when launching as a Java app I could put breakpoints into Ruby code, but that doesn't seem to work for me. So far the only way I've been able to debug both Java and Ruby at the same time is to launch the application as Java with a command line that starts the Ruby script through rdebug-ide and then launching a second debugging sessions, this time using a "Ruby remote debug" run configuration to connect to the Ruby debug port I opened in the first session.
This is more of a pain than I was hoping for. Is it necessary to run 2 separate debug sessions like this (one for Java and one for Ruby)? Or is there some way to launch my app once and hit breakpoints in both Ruby and Java?
Thanks a lot for your help.
I still can't figure out how to get this to work with only a single debug session. Is it necessary to always run 2 separate debugging sessions (one for Java and one for Ruby) or is it possible to do with just one?
Indeed we don't support simultaneous debug Ruby and Java application, the only way to reach this is to use 2 different debug configurations.
However feel free to submit a feature request at: http://youtrack.jetbrains.net/issues/RUBY
I did enter this a couple of weeks ago but so far it's not getting much love: http://youtrack.jetbrains.net/issue/IDEA-70293.
Out of curiosity, what does the setting you recommended (-Dforce.jruby.jit=true) do? I seem to be able to get breakpoints to be hit in my Ruby code whether I have this set or not. What difference in behaviour should I see when I use this setting?
Well I see, that you've created an issue in IDEA project, thanks.
As far as JVM option is concerned, this is my fault, I appologize, the correct option seems to be this one:
This option as described in jruby interpreter sets the execution mode most suitable for debugger functionality.
Previous option just enabled JustInTime compilation.
--debug option should allow Java connect to JRuby running process.
I'm also looking for a way to debug Java & Ruby in the same session. Has any progress been made on this in the last 2 years?
For those looking to do this in intelliJ 2019, simply setup you application for ruby debugging as normal and then add the following to the "Ruby arguments" line on the "Edit Configuration" screen:
Once you start the process to debug the Ruby code, you will then be able to go the the "Run" menu and attach to the Java process that is running Jruby and debug you java code as well