# Unable to call Java from a Ruby Script

**URL:** <https://www.ruby-forum.com/t/unable-to-call-java-from-a-ruby-script/64515>\
**Category:** Ruby\
**Created:** [August 9, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/unable-to-call-java-from-a-ruby-script/64515 "2006-08-09T18:35:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trupti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@trupti](https://www.ruby-forum.com/u/trupti)\
**Post date:** [August 9, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/unable-to-call-java-from-a-ruby-script/64515/1 "2006-08-09T18:35:34Z")

</div>

I am trying to call a java class from my ruby script. I have installed  
JRuby and JRUBY\_HOME and JAVA\_HOME environment variables are pointing  
to the correct locations. However I am not able to run a ruby file which  
uses watir using jruby.

If I use this command java -jar jruby.jar myrubyfile.rb , it gives the  
following error

* * *

myrubyfile.rb:2:in `require’: No such file to load – watir (LoadError)  
from myrubyfiles.rb:2

* * *

Even if I dont use watir it throws a similar error for the rest of the  
ruby files used in the script ,like require ‘test/unit’ from the testing  
framework

If I just run the script with the script name from the command prompt,  
it gives the following error.

* * *

c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_re quire': no such file to load -- java (LoadError) from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`re  
quire’  
from myrubyfiles.rb:2

* * *

I know this is some sort of classpath error , however everything seems  
to have been set, its still not working . What do you think is going  
wrong??

---

<div class="post-metadata">

**Author:** ![trupti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@trupti](https://www.ruby-forum.com/u/trupti)\
**Post date:** [August 10, 2006, 1:11am UTC](https://www.ruby-forum.com/t/unable-to-call-java-from-a-ruby-script/64515/2 "2006-08-10T01:11:40Z")

</div>

Hello again Trupti…

A few things I mentioned in my JRuby email…hopefully this one reaches  
you:

- WATIR will not currently work in JRuby because we do not have a win32  
OLE  
library. This is planned, but nothing has been started yet.
- You should look at the JRuby shell and bat scripts to see how to  
propertly  
invoke JRuby. Invoking the jar directly does not currently work, because  
there are system properties that must be passed to it.

I would recommend you set the env vars you have, JRUBY\_HOME and  
JAVA\_HOME,  
and then run either the shell or batch scripts on the script you want to  
run, as in:

jruby myrubyfile.rb
