This is almost certainly something I’m doing wrong, but I find myself
unable
to successfully modify the Java Classpath from JRuby code. The context
is
‘rake’, in which I want to add some things to the Java classpath, then
run
some JRuby unit tests which require these.
Apparently, by Google-fu is weak. On the basis of things I did find,
I
tried:
Modifying the global $CLASSPATH
Adding to “$:” (I found a page describing the unification of the Ruby
and
Java loadpaths).
Modifying ENV[‘CLASSPATH’]
… all to no avail. I have also read that I can ‘require foo.jar’ to
add a
jar file, but in this case it’s a directory of classfiles I’d like to
add.
Can anyone point me to something that should work?
This is almost certainly something I’m doing wrong, but I find myself unable to successfully modify the Java Classpath from JRuby code. The context is ‘rake’, in which I want to add some things to the Java classpath, then run some JRuby unit tests which require these.
Apparently, by Google-fu is weak. On the basis of things I did find, I tried:
Modifying the global $CLASSPATH
Adding to “$:” (I found a page describing the unification of the Ruby and Java loadpaths).
Modifying ENV[‘CLASSPATH’]
… all to no avail. I have also read that I can ‘require foo.jar’ to add a jar file, but in this case it’s a directory of classfiles I’d like to add. Can anyone point me to something that should work?
Look at the following example:
require ‘java’
begin
java_import ‘org.apache.commons.io.CopyUtils’
rescue NameError => e
puts “It fails…”
puts e.inspect
end
I indicated originally, that I’d tried adding to $CLASSPATH. I did, but
apparently I did something else wrong. It’s working fine for me now,
after
everyone’s fine advise. Thanks again.