[jruby-user] Debugging JRuby running within a Java process

Chason Choate <[email protected]> Sat, 10 Jan 2015 14:03:14 -0600
Newsgroups gmane.comp.lang.jruby.user
Message-ID <CADgFOvrzt2V6ibT7Bb01nOH1AuVV-UE96RL=GD+_GEwt6-oOPA@mail.gmail.com>
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
stack.

We have a Java app that uses the JRuby ScriptingContainer
<http://jruby.org/apidocs/org/jruby/embed/ScriptingContainer.html> to
launch the rails app.

ScriptingContainer ruby = new
ScriptingContainer(LocalContextScope.THREADSAFE,
LocalVariableBehavior.TRANSIENT);
...
File rackup = new File(railsPath, "config.ru");
rackupContent = FileUtils.fetchFile(rackup, StandardCharsets.UTF_8.name());
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
<https://github.com/square/rack-servlet> which allows the network requests
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
<https://github.com/jruby/jruby/wiki/UsingTheJRubyDebugger> 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 launched
could be changed.


-- 
Thanks for your time,
Chason Choate