# Any JRUBY programmers out there? Problems specifying RUBYLIB

**URL:** <https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914>\
**Category:** Ruby\
**Created:** [May 11, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914 "2007-05-11T17:08:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 11, 2007, 5:08pm UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914/1 "2007-05-11T17:08:43Z")

</div>

I would like to run jruby on either pure Windows, or Cygwin. This works  
fine as long as I  
only use the standard library which comes with jruby. I can’t make it,  
however, search  
additional libraries I have put in non-standard places. For example, I  
have a Ruby module  
placed in …\SOMEPATH\lib\net\ssh, which I require from my Ruby  
program by

require ‘net/ssh’

I guess I have now to set my RUBYLIB environment variable, so that jruby  
can resolve the  
require statement. I tried several possible variations of how to set  
RUBYLIB, but always  
get a “no such file to load”.

For example under cygwin (bash shell), even a

cd SOMEPATH # go to the directory containing the library  
RUBYLIB=. jruby MYPROGRAM.rb

or

RUBYLIB=lib jruby MYPROGRAM.rb

does not find the library. And in a Windows command shell,

set RUBYLIB=…\SOMEPATH\lib\net\ssh

or, respectively,

set RUBYLIB=…\SOMEPATH\lib\net\ssh\lib

doesn’t make jruby find the library either.

I would already be glad finding a solution for either Windows or Cygwin,  
but of  
course being able to get it running under both would be even better. I  
understand  
that doing it for Cygwin is trickier though, because Jruby is based on  
Java and  
hence doesn’t understand Cygwin pathes.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 11, 2007, 5:29pm UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914/2 "2007-05-11T17:29:46Z")

</div>

Ronald F. wrote:

> or
> 
> RUBYLIB=lib jruby MYPROGRAM.rb

Hi,

Ok, what you should do here is not use RUBYLIB at all. JRuby does  
understand RUBYLIB, but it won’t do what you expect. Instead, use the -I  
parameter to JRuby:

jruby -I lib MYPROGRAM.rb

This will work just fine on both Win32 and Cygwin.

Cheers

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 11, 2007, 5:56pm UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914/3 "2007-05-11T17:56:49Z")

</div>

“Ronald F.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I guess I have now to set my RUBYLIB environment variable, so that  
> jruby can resolve the require statement. I tried several possible  
> variations of how to set RUBYLIB, but always get a “no such file to  
> load”.

Which version of jruby are you using? This is something that is  
supposedly fixed in 1.0RC1. (see  
[http://jira.codehaus.org/browse/JRUBY-79](http://jira.codehaus.org/browse/JRUBY-79) and  
[http://dist.codehaus.org/jruby/](http://dist.codehaus.org/jruby/) )

In earlier versions than that, you can add a directory by setting the  
java system property jruby.lib. Note that this is not an  
environmental variable that you set, but something you set in the java  
environment before you call out to jruby. (My context with jruby is  
in using it as a scripting engine in some larger java program; I don’t  
use it standalone myself. For standalone ruby, I have ruby.)

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 14, 2007, 10:43am UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914/4 "2007-05-14T10:43:29Z")

</div>

> Ok, what you should do here is not use RUBYLIB at all. JRuby does  
> understand RUBYLIB, but it won’t do what you expect. Instead,  
> use the -I  
> parameter to JRuby:
> 
> jruby -I lib MYPROGRAM.rb
> 
> This will work just fine on both Win32 and Cygwin.

Thank you very much.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 16, 2007, 11:34pm UTC](https://www.ruby-forum.com/t/any-jruby-programmers-out-there-problems-specifying-rubylib/103914/5 "2007-05-16T23:34:20Z")

</div>

I currently use RUBYLIB in a similar way. It’s especially handy for  
one-off command-line scripts:

.bashrc -  
export RUBYLIB=c:/cvs-main/db-building/scripts

…

ruby -e “require ‘lsml’; $p.parse{ |r| r.ids.each {|id| if id.type ==  
‘reg’ then puts id end}}” file.xml

where the lsml library has a bunch of pre-canned tools set up. It would  
be a drag to have to specify -I … every time.

The problem I ran into with jruby is that it doesn’t know about the  
cygwin mounts (/cygdrive/c/) and splits on “:” instead of “;” - which  
makes the c:/ notation problematic. (Incidentally, the cygwin ruby  
handles both ; and : in RUBYLIB)

I posted a fix to jira - where it uses File.pathSeparator instead of :,  
and have been happy ever since.

[http://jira.codehaus.org/browse/JRUBY-938](http://jira.codehaus.org/browse/JRUBY-938)

Ola - I’m left curious as to what RUBYLIB is supposed to do, if not  
handle this case, and if so, is there another (perhaps more appropriate)  
way to do what I’m suggesting?

Thanks,  
Scott

Ronald F. wrote:

> > Ok, what you should do here is not use RUBYLIB at all. JRuby does  
> > understand RUBYLIB, but it won’t do what you expect. Instead,  
> > use the -I  
> > parameter to JRuby:
> > 
> > jruby -I lib MYPROGRAM.rb
> > 
> > This will work just fine on both Win32 and Cygwin.
> 
> Thank you very much.
> 
> Ronald
