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.
on 2015-01-10 22:04
on 2015-01-12 09:18
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 <
on 2015-01-12 19:26
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 <
on 2015-01-13 18:28
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 <