today I gave JRuby a try to use it with Apache's Mahout. But I have a problem with the debugger. When I put the debugger statement on a specific place, it doesn't stop there. It stops later at the end of the script, and then of course none of the variables are available. This is my Gemfile:
source 'https://rubygems.org'
platform :jruby do
gem "jruby_mahout"
gem "ruby-debug"
end
This is the Script:
require 'rubygems'
require 'ruby-debug'
puts "I am called"
debugger
puts "I should not be called before the debugger"
But the output is:
I am called
/usr/local/rvm/gems/jruby-1.7.3#mahout/gems/ruby-debug-base-0.10.4-java/lib/ruby-debug-base.rb:215 warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
I should not be called
/usr/local/rvm/gems/jruby-1.7.3#mahout/gems/ruby-debug-0.10.4/cli/ruby-debug/interface.rb:129
finalize if respond_to?(:finalize)
(rdb:1)
I'm wondering why there is this warning tracing (e.g. set_trace_func) will not capture all events without --debug flag, because I started the script with jruby test.rb --debug
I installed JRuby 1.7.3 with RVM on my OS X 10.8, and when calling jruby -version I get this output:
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_43-b01-447-11M4203 [darwin-x86_64]
NameError: undefined local variable or method `rsion' for main:Object
(root) at -e:1
Maybe the installation is broken, or I'm doing sth wrong. Any suggestions how to solve this?
I solved it on my own. After a long time of trying, I accidentially putted the --debug statement between:
jruby --debug test.rb
It's weird, but now it works as expected.
Related
I have a set of ruby code (which is actually a gem that I extracted and the lib folder contains a bunch of .rb (ruby code). I have Eclipse Aptana Studio 3 plugin setup and have JRuby
$ jruby -v
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on Java HotSpot(TM) 64-Bit Server VM 1.
6.0_45-b06 [Windows 7-amd64]
I need to execute a ruby file: /lib/my_rubycaller.rb, which is like the following:
#dependencies for part0
require 'rubygems'
require 'mechanize'
#dependencies for abcd
require "rexml/document"
require "find"
require "ostruct"
require 'somedependency'
class MyRubyCaller
def get_somedata(first_param,b,c)
<some code goes here>
return test_sr
end
end
Now at the Aptana Studio 3 Terminal View, I typed the following:
$ jruby -S lib/my_rubycaller.rb
LoadError: no such file to load -- somedependency
require at org/jruby/RubyKernel.java:1054
require at c:/Users/mkorapat/MyProjects/jruby-1.7.4/lib/ruby/shared/rubygems/cor
e_ext/kernel_require.rb:51
(root) at my_rubycaller.rb:11
Inside my_rubycaller # line# 11, I have the require statement. I don't know what I am doing wrong. I am new to Ruby development, but since I am versatile with Eclipse, just stuck to Aptana and JRuby is just because I thought perhaps I could leverage some additional benefits that it has to offer. But it might still be a matter of time for me to go with Ruby as against JRuby, but still, I wonder how it will help me in this scenario.
Thanks in advance for the help.
Regards
Mahesh
just changed require to require_relative - since apparently my JRuby version seems to use ruby 1.9 and I see that require_relative is the way to go. Refer to Ruby 'require' error: cannot load such file. So long so good. Thanks.
I want to use pry from within irb/debugger, so I can:
invoke step, next, continue, finish inside of pry
still be able to set breakpoints, etc.
What I did is the following:
$ gem install pry
$ gem install debugger
$ gem install debugger-pry
In the code I have inserted require 'debugger'; debugger
Then I start my program with ruby example, the irb promp starts and as described here it should display the pry command on help, but it does not.
ruby-debug help v1.5.0
...
(rdb:1) pry
*** Unknown command: "pry". Try "help".
Any idea how I could check whether it is installed correctly or what am I missing?
I think you need:
require 'debugger/pry'
you could add it to the top of your example.rb file.
I am trying to execute my CGI program from WEBrick CGIhandler and kept failing with 'loaderror' of gem libraries. Is someone seen following behavior before? How could I get my CGI scripts to search valid gem location?
[Situaltion]
When I ran CGI scripts that requires 'mysql2' library via Webrick server, I got a following error:
ERROR CGIHandler: /home/charles/code/svr/lib/cgitest.rb:
/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mysql2/version (LoadError)
Comment this particular 'require' out from cgitest.rb makes this script work so looks just failed to load this library. Added "puts Gem.path" to the script indicates CGIHandler is looking to following directories to find gem;
["/home/charles/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1", "/.gem/ruby/1.9.1"]
while actual GEM:HOME and GEM:PATH are following;
["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-p194#global"]
I think I am missing something very simple but could not figure them out. Really appreciate if someone lead me to the right direction. Any input would be highly welcome.
[Environment]
Using RVM to install Ruby 1.9.3 to Ubuntu Server 12.4 with bunch of gems including "mysql2" library. And the script can load 'mysql2' when I run from local.
$which ruby
/home/charles/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
$irb
1.9.3-p194 :001 > Gem.path
=> ["/home/charles/.rvm/gems/ruby-1.9.3-p194", "/home/charles/.rvm/gems/ruby-1.9.3-
p194#global"]
1.9.3-p194 :002 > require 'mysql2'
=> true
You need to use wrapper instead of bin/ruby:
/home/charles/.rvm/wrappers/ruby-1.9.3-p194/ruby
This will ensure you load proper environment when starting ruby.
Code inspection in the IntelliJ IDEA editor reports a LoadError "no such file to load" on the code
require 'state_machine'
The gem is installed locally. From the command line:
~$ echo $RUBYOPT
rubygems
~$ irb
irb(main):001:0> require 'state_machine'
=> true
So Ruby and Rubygems are playing nicely together. The IDEA Ruby plugin's project settings even lists the gem, so why can't the editor see it?
Ruby version 1.8.7, IntelliJ IDEA 10.5.4.
This gem must be specified in the Gemfile, refer to help.
I'm familiarizing myself with some JRuby code, and I'd like to be able to place a breakpoint in the code and run (as usual) from the command-line, having it break into the debugger when it gets to that point. Is there something I can put in my code to force JRuby to break into the debugger?
I've tried running jruby -r debug foo.rb (instead of the usual jruby foo.rb), and then setting a breakpoint with b bar.py:98, and then continuing. But the debugger stops every time there's an exception, and there seem to be a lot of them before it gets to the line of code I'm interested in. I'd like to be able to put the "break-into-debugger" line(s) in my code and run jruby foo.rb and have the first place the debugger stops be at that line.
(i.e. I'm looking for the Ruby/JRuby equivalent of import pdb;pdb.set_trace() in Python.)
You could try Netbeans Ruby IDE, it has JRuby interpreter and debugging tools embedded and you can debug visually in the IDE directly.
If using an IDE is not an option for you, just install de debug gem into your JRuby distro and use it via debugger command:
Manually download the ruby-debug-base-0.10.3.1-java.gem from debug-commons to a local directory.
Install the Gem into your JRuby Gem repository:
jruby -S gem install -l ruby-debug-base-0.10.3.1-java.gem
Install ruby-debug gem:
jruby -S gem install --ignore-dependencies ruby-debug
The debugger command should work now.
# test.rb
require 'rubygems'
require 'ruby-debug'
debugger
# run like this:
jruby --debug -S rdebug test.rb
More information on Netbeans wiki, rdebug wiki and JRuby wiki
require 'rubygems'
require 'ruby-debug'
debugger
I am using JRuby 1.7.3 (1.9.3p385) on Windows 7.
Contrary to what people say, there does not seem to be a version of ruby-debug preinstalled with JRuby. However, I installed it by running gem install ruby-debug. I start the debugger in my code like this:
require 'rubygems'
require 'ruby-debug'
debugger
You should call the debugger method everywhere that you want to have a breakpoint.
I ran the code like this:
jruby --debug program.rb
The --debug option is optional, but without it you get a warning that "tracing (e.g. set_trace_func) will not capture all events without --debug flag".
Another answer on here used the -S rdebug option on the command line. That option is not necessary for debugging and it makes the debugger start at the very beginning of your program. Just call the debugger method to start the debugger when you need it; don't use that option.
Even without the ruby-debug gem, it seems like there is still some kind of basic debugging built in to JRuby via debug.rb. You can simply write load 'debug.rb' in a file to start a debugger going. It prints out some junky messages ("Debug.rb" and "Emacs support available.") but it seems to work.