Debugging JRuby running within a Java process

Hello world!

So i’m currently trying to figure out how to debug a JRuby on Rails app
that is running within a Java application. I’ll attempt to describe the

We have a Java app that uses the JRuby ScriptingContainer to
launch the rails app.

ScriptingContainer ruby = new

File rackup = new File(railsPath, “”);
rackupContent = FileUtils.fetchFile(rackup,;
ruby.put(“rackup_script”, rackupContent);
ruby.put(“rackup_file”, rackup.getAbsolutePath());
IRubyObject railsApp = ruby.parse(“require ‘rack’;
Rack::Builder.new_from_string(rackup_script, file=rackup_file)”).run();

Then we pass the rails application to the rack servlet which allows the network
to flow into the rails app.

return new RackServlet(new JRubyRackApplication(railsApp));

At this point the app is running fine i’m just not sure how to start
debugging. Here are some of the things i’m confused about.

  1. I’ve read this article but I am not
    sure how to start the rails app with: jruby --debug -S rdebug
  2. Would it be possible to use standard java debugging with this setup?
  3. Has anyone went down this path before and came out with a better
    solution, as far as launching the rails app?
    • The Java portion in mandatory but the way the rails app is
      could be changed.

I would suggest using pry-remote (pry-remote | | your community gem host)
instead. This would require it to be part of your gemfile, but this
work perfectly: this is how we debug server applications once deployed
war files (but only if they go into specific exceptions).

Good luck.

On Sat, Jan 10, 2015 at 9:03 PM, Chason Choate <

Thanks Christian,

I’ll be sure to give that a shot and let everyone know how it unfolds.

On Mon, Jan 12, 2015 at 1:17 AM, Christian MICHON <

So here’s what I experienced while trying to debug jruby within a java

Using pry and pry-remote I was able to attach to the jruby process and
a breakpoint. Whenever I typed something into pry-remote I got this

output error: java.lang.IncompatibleClassChangeError: Found class
jline.Terminal, but interface was expected

After perusing our codebase we don’t have a dependency on jline anywhere
i’m not sure what’s causing this.

Next I tried ruby-debug. I was able to get the debugger working and
excepting my input. One issue I noticed was that when I wanted to “next”
the next line it behaved like “step into”. I have found that you have to
run jruby with the “–debug” flag for this behavior to work properly.
I am running jruby from within Java I used this:
“-Djruby.debug.fullTrace=true”. Where i’m currently stuck is if I start
rails app in development “export RAILS_ENV=development” and pass
“-Djruby.debug.fullTrace=true” to the java process my rails app hangs
shortly after processing application.rb.

I’ll continue to work on this but if anyone has any insight please toss
my way. It will be much appreciated.

On Mon, Jan 12, 2015 at 11:25 AM, Chason Choate <