Forum: JRuby Debugging JRuby running within a Java process

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E413e67f84dd83d35973e4251790bd8c?d=identicon&s=25 Chason Choate (Guest)
on 2015-01-10 21:04
(Received via mailing list)
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/Scripting... 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/UsingTheJRubyD... 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.
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2015-01-12 08:18
(Received via mailing list)
I would suggest using pry-remote (https://rubygems.org/gems/pry-remote)
instead. This would require it to be part of your gemfile, but this
would
work perfectly: this is how we debug server applications once deployed
as
war files (but only if they go into specific exceptions).

Good luck.

On Sat, Jan 10, 2015 at 9:03 PM, Chason Choate <
E413e67f84dd83d35973e4251790bd8c?d=identicon&s=25 Chason Choate (Guest)
on 2015-01-12 18:26
(Received via mailing list)
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 <
E413e67f84dd83d35973e4251790bd8c?d=identicon&s=25 Chason Choate (Guest)
on 2015-01-13 17:28
(Received via mailing list)
So here's what I experienced while trying to debug jruby within a java
process.

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

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
so
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"
to
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.
Since
I am running jruby from within Java I used this:
"-Djruby.debug.fullTrace=true". Where i'm currently stuck is if I start
my
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
it
my way. It will be much appreciated.

On Mon, Jan 12, 2015 at 11:25 AM, Chason Choate <
This topic is locked and can not be replied to.