Configuring gems in eclipse

前端 未结 4 545
予麋鹿
予麋鹿 2021-01-13 00:00

I\'m trying to work on a vagrant / chef project in eclipse. I\'m fairly new to both technologies and a little rusty with ruby. I\'ve installed rdt and have a ruby project wi

4条回答
  •  借酒劲吻你
    2021-01-13 00:29

    I was having a very similar problem of getting Eclipse to recognize my installed gems. I was using rvm, with the default pointing to ruby 2.1.0. The ruby code that I was debugging had a single require 'mail' at the top. When running or debugging the script, the console displayed an error:

    /Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mail (LoadError)
         from /Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    `
    '

    Eclipse had the correct ruby configured in its Preferences > Ruby > Interpreters: /Users/username/.rvm/rubies/ruby-2.1.0/bin/ruby

    I knew the mail gem was installed for that ruby, outside of Eclipse:

    $ gem which mail
    /Users/username/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail.rb
    

    I tried @Don Kirkby's suggestion of adding -rubygems as an Interpreter argument in Debug Configurations, but it still wasn't working.

    What DID get it working, oddly enough, was to add the GEM_HOME and GEM_PATH variables to the Environment section of the Debug Configurations.

    I found the correct values (set by rvm, I presume) by echoing them in the terminal, outside of Eclipse:

    $ echo $GEM_HOME
    /Users/username/.rvm/gems/ruby-2.1.0
    $ echo $GEM_PATH
    /Users/username/.rvm/gems/ruby-2.1.0:/Users/username/.rvm/gems/ruby-2.1.0@global
    

    Adding those two as environment variables in Debug Configurations > Environment tab did get debugging working in Eclipse, using the Ruby Built-In Debugger as the debug Engine in Preferences. Incidentally, I tried using 'Fast Ruby Debugger (ruby-debug)' engine, but got this error:

    dyld: lazy symbol binding failed: Symbol not found: _rb_vm_get_sourceline
      Referenced from: /Users/username/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/debugger-1.6.8/ruby_debug.bundle
      Expected in: flat namespace
    
    dyld: Symbol not found: _rb_vm_get_sourceline
      Referenced from: /Users/username/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/debugger-1.6.8/ruby_debug.bundle
      Expected in: flat namespace
    

    Sidenote: Trying to hunt down a fix to the Symbol not found error for the Fast Ruby Debugger engine led me to this thread: Debugging in ruby 1.9 , which seems to imply that neither ruby-debug nor debugger gem is appropriate to use with ruby 2.0+, and instead recommended the byebug gem. But since I don't see a way to use byebug with Eclipse, I just ended up using the Ruby Built-In Debugger engine with the debugger and ruby-debug-ide gems:

    $ gem install debugger
    Successfully installed debugger-1.6.8
    $ gem install ruby-debug-ide
    Successfully installed ruby-debug-ide-0.4.26
    

    which I got from this post: https://endocode.com/blog/2012/09/03/debugging-ruby-1-9-3-applications-in-eclipse/

    Hopefully this is helpful to somebody who's trying to get Ruby 1.9/2.0+ debugging working with Eclipse.

提交回复
热议问题