Any JRUBY programmers out there? Problems specifying RUBYLIB


#1

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


#2

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)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.


#3

“Ronald F.” 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 and
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.)


#4

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


#5

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

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