Forum: JRuby How to properly setup requires

651b17fe14e066397d78961511a1c214?d=identicon&s=25 D M (Guest)
on 2012-06-28 02:04
(Received via mailing list)
I am working on a little gem in Netbeans to relearn Ruby and JRuby and
am having path issues between Netbeans and running it in the CL.

$LOAD_PATH in netbeans gives

/home/david/projects/http-proxy/lib-I/home/david/projects/http-proxy/spec
/home/david/apps/jruby/lib/ruby/site_ruby/1.9
/home/david/apps/jruby/lib/ruby/shared
/home/david/apps/jruby/lib/ruby/1.9

in CL it is

/home/david/apps/jruby/lib/ruby/site_ruby/1.9

/home/david/apps/jruby/lib/ruby/shared

/home/david/apps/jruby/lib/ruby/1.9

Using require_relative works for both, but I don't recall ever having to
use that method.

Using require and actually not getting errors back requires this ugly
hack

unless Dir.exists? "#{Dir.pwd}/lib"
   $LOAD_PATH << "#{Dir.pwd}"
 else
   $LOAD_PATH << "#{Dir.pwd}/lib"
 end


I don't remember ever having to set $LOAD_PATH for either Ruby or JRuby.

Is there a better way to require files in the gem?
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2012-06-29 20:43
so what's the exact problem here?
651b17fe14e066397d78961511a1c214?d=identicon&s=25 D M (Guest)
on 2012-06-29 23:06
(Received via mailing list)
The exact problem is why do I have to explicitly set $LOAD_PATH to only
recognize the path of the application? I don't recall ever having to do
that in ruby/jruby before and I have never had to do that in any other
language.

Why does JRuby not know what the path is to the currently executing .rb
file.

given main.rb(which lives in lib) and http_proxy/http.rb why cant JRuby
require http.rb with a simple require 'http_proxy/http' in main.rb
without all the ridiculous $LOAD_PATH contortions?
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.