Is there a reason why a gem would run in jruby -S irb, but not in a script invoked with jruby?

$ jruby -S irb
ree-1.8.7-2011.03 :001 > require ‘tweetstream’
=> true

however…

$ jruby test.rb
LoadError: no such file to load – tweetstream
require at org/jruby/RubyKernel.java:1038
(root) at test.rb:1

which is just…

$ cat test.rb
require ‘tweetstream’

Please let me know if I can provide any other info.

Thanks
Jon

Although I will add that while it loads in irb, it doesn’t seem to
actually
work…so there is the question of why it “loads,” but also, what might
be a
common cause as to why a gem doesn’t work with jruby, and what I can do
to
fix it.

2011/10/25 Jonathan C. [email protected]

On Tue, Oct 25, 2011 at 12:22 AM, Jonathan C.
[email protected]wrote:

$ jruby -S irb
ree-1.8.7-2011.03 :001 > require ‘tweetstream’
=> true

ree? sounds like not jruby, but maybe I’m misreading something here.
Solution further down in this email.

however…

$ jruby test.rb
LoadError: no such file to load – tweetstream
require at org/jruby/RubyKernel.java:1038
(root) at test.rb:1

% jruby -e ‘require “tweetstream”; puts :OK’
LoadError: no such file to load – tweetstream
require at org/jruby/RubyKernel.java:1038
(root) at -e:1

The problem here (reproduced for you) is that you have not yet required
rubygems - you must require rubygems for jruby (at least in 1.8.7 mode)
to
find any gems you have installed.

% jruby -e ‘require “rubygems”; require “tweetstream”; puts :OK’
OK

Hope this clarifies things :slight_smile:

-Jordan

Sorry, replied to wrong post AND got beaten to the punch…

…Ill go sit in a corner.

Do you need to put

require ‘rubygems’

In there somewhere? Maybe it is being called in one but not the other?

No corners necessary! I appreciate the help (a lot).

Ah, the require ‘rubygems.’ That makes sense. I guess the question now:
why
is “jruby -S irb” sensitive to the version of irb that I have? My guess
would be that the -S irb is simply running the ruby REPL code in jruby,
and
isn’t it’s own implementation, so it detects that the default ruby
install,
and then runs the irb code from that install, but using jruby? So if I
am
using rvm to install various version of ruby, how would I choose which
irb
to run? Is jruby -S gem the same way? How can I control which version of
ruby the jruby gem installer is working through? I think I’m having
version
and whatnot issues… can rvm+gemspec handle this? It sounds like even
if
you do rvm jruby-head@mygemspec, gem install whatever won’t actuall
install
to jruby?

Thanks!
Jon

2011/10/25 Jeffrey J. [email protected]