Forum: JRuby Require -Cannot load such file --java

Posted by Nicole Villette (nvillette)
on 2013-02-11 23:00
Hello,

I really need some help.  I installed jruby and I want to experiment
with the java robot class to assist in clicking on flash objects.

I am getting a load error on this statement:
require "java"

custom_require.rb:55: in `require': cannot load such file -- java
(LoadError)


I read that you must require java before using jruby, but I don't know
what the problem is.  I think I have my paths set up correctly.


This is what I have in my bash_profile

export JAVA_HOME='/usr/libexec/java_home -v 1.6'
export PATH=$PATH:${JAVA_HOME}/bin:bin
export JRUBY_HOME='/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2'
export PATH=$PATH:$JRUBY_HOME/bin


Please help.
Thanks in advance
Posted by Hiro Asari (Guest)
on 2013-02-11 23:05
(Received via mailing list)
Are you using rvm or such,  and calling jruby as 'ruby'  instead? I 
suspect
you are calling a non-jruby somehow.
Posted by Thomas E Enebo (Guest)
on 2013-02-11 23:08
(Received via mailing list)
To add an additional suggestion: try 'ruby -v' or whatever you are 
calling -v.

-Tom

On Mon, Feb 11, 2013 at 4:04 PM, Hiro Asari <asari.ruby@gmail.com> 
wrote:
>> I am getting a load error on this statement:
>> This is what I have in my bash_profile
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>



--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo@gmail.com
Posted by Nicole Villette (nvillette)
on 2013-02-11 23:24
Hiro Asari wrote in post #1096387:
> Are you using rvm or such,  and calling jruby as 'ruby'  instead? I
> suspect
> you are calling a non-jruby somehow.


I just installed rvm so yes I am using that.  I had the same issue 
before installing it.

ruby -v  and jruby -v gives me the same results:

jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit 
Server VM 1.6.0_35-b10-428-11M3811 [darwin-x86_64]
Posted by Keith B. (keith_b)
on 2013-02-11 23:47
(Received via mailing list)
Nicole -

What is the output when you run:

java --version

and:

which java

..from the command line?

- Keith

---
Keith R. Bennett
http://about.me/keithrbennett
Posted by Nicole Villette (nvillette)
on 2013-02-11 23:54
Keith B. wrote in post #1096391:
> Nicole -
>
> What is the output when you run:
>
> java --version
>
> and:
>
> which java
>
> ..from the command line?
>
> - Keith
>
> ---
> Keith R. Bennett
> http://about.me/keithrbennett


java version "1.6.0_35"

which java
/usr/bin/java
Posted by Thomas E Enebo (Guest)
on 2013-02-12 00:25
(Received via mailing list)
I just realized you are setting JRUBY_HOME and also adding that to
your PATH.  With RVM you should not really need to do that (unless you
want to run both JRuby and another Ruby at same time -- I instead
suggest using aliases like: alias mri19='rvm 1.9.3 do ruby'.

Can you try removing those, reload your shell and then 'do rvm use
jruby'.  If that does not work, then can you email back 'rvm info'
output.  If I had to guess on your problem I would say there is some
weird environment confusion between what you are setting and what RVM
is setting.

-Tom

On Mon, Feb 11, 2013 at 4:54 PM, Nicole Villette <lists@ruby-forum.com> 
wrote:
>>
>
>
>



--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo@gmail.com
Posted by Robin McKay (robin2)
on 2013-02-12 11:04
Should one use    require 'java'    or    include Java     or does it
not make any difference?

For some reason I have the impression that include Java is the current
recommended approach but I can't remember where I got that idea.

Both seem to work on my PC.

...R
Posted by Nicole Villette (nvillette)
on 2013-02-12 15:08
Thomas E Enebo wrote in post #1096396:
> I just realized you are setting JRUBY_HOME and also adding that to
> your PATH.  With RVM you should not really need to do that (unless you
> want to run both JRuby and another Ruby at same time -- I instead
> suggest using aliases like: alias mri19='rvm 1.9.3 do ruby'.
>
> Can you try removing those, reload your shell and then 'do rvm use
> jruby'.  If that does not work, then can you email back 'rvm info'
> output.  If I had to guess on your problem I would say there is some
> weird environment confusion between what you are setting and what RVM
> is setting.
>
> -Tom
>
> On Mon, Feb 11, 2013 at 4:54 PM, Nicole Villette <lists@ruby-forum.com>
> wrote:
>>>
>>
>>
>>Thanks again for your response. Yes, I am setting JRUBY_HOME because I wasn't 
initially using rvm.  Things weren't working so I thought if I install rvm it 
would help.  Anyway, I removed those entries and still no luck.  I see there is 
something wrong...here is the rvm info output.

system:
    uname:       "Darwin ts-spare03.targetspot.local 11.4.2 Darwin 
Kernel Version 11.4.2: Wed May 30 20:13:51 PDT 2012; 
root:xnu-1699.31.2~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.7/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release 
(x86_64-apple-darwin11)"
    zsh:         "/bin/zsh => zsh 4.3.11 (i386-apple-darwin11.0)"

  rvm:
    version:      "rvm 1.18.6 (stable) by Wayne E. Seguin 
<wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> 
[https://rvm.io/]"
    updated:      "20 hours 3 minutes 59 seconds ago"

  ruby:
    interpreter:  "No"
    version:      "`java'"
    date:         "No `java' exists at /usr/libexec/java_home -v 
1.6/bin/java, please double-check JAVA_HOME."
    platform:     "No `java' exists at /usr/libexec/java_home -v 
1.6/bin/java, please double-check JAVA_HOME."
    patchlevel:   "No `java' exists at /usr/libexec/java_home -v 
1.6/bin/java, please double-check JAVA_HOME."
    full_version: "No `java' exists at /usr/libexec/java_home -v 
1.6/bin/java, please double-check JAVA_HOME."

  homes:
    gem:          "/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2"
    ruby:         "/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2"

  binaries:
    ruby: 
"/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2/bin/ruby"
    irb: 
"/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2/bin/irb"
    gem: 
"/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2/bin/gem"
    rake: 
"/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2@global/bin/rake"

  environment:
    PATH: 
"/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2/bin:/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2@global/bin:/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2/bin:/Users/TargetSpot0054/.rvm/bin:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Ruby/Gems/1.8/gems/selenium-webdriver-2.25.0/lib:/usr/local/Cellar/jruby:/Library/Ruby/jruby-1.1.5:/usr/local/Cellar/ruby/1.9.3-p194/lib/ruby/gems/1.9.1/gems:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:/usr/X11/bin:/usr/local/bin/ruby:/Library/Ruby:/usr/libexec/java_home 
-v 1.6/bin:bin"
    GEM_HOME:     "/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2"
    GEM_PATH: 
"/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2:/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2@global"
    MY_RUBY_HOME: "/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2"
    IRBRC:        "/Users/TargetSpot0054/.rvm/rubies/jruby-1.7.2/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

>
>
>
> --
> blog: http://blog.enebo.com       twitter: tom_enebo
> mail: tom.enebo@gmail.com
Posted by Nicole Villette (nvillette)
on 2013-02-12 15:09
Robin McKay wrote in post #1096432:
> Should one use    require 'java'    or    include Java     or does it
> not make any difference?
>
> For some reason I have the impression that include Java is the current
> recommended approach but I can't remember where I got that idea.
>
> Both seem to work on my PC.
>
> ...R


I am new to jruby, but i tried both and when I use include Java, I get 
the following:

Jrubytest_testsuite.rb:13: in `<main>': uninitialized constant Java 
(NameError)
Posted by Keith B. (keith_b)
on 2013-02-12 15:32
(Received via mailing list)
Nicole -

My JAVA_HOME is set to:

>echo $JAVA_HOME
/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home

With JAVA_HOME correctly set, you should be able to do this:

>$JAVA_HOME/bin/java -version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

Could you try changing your JAVA_HOME variable?

- Keith

---
Keith R. Bennett
http://about.me/keithrbennett
Posted by Nicole Villette (nvillette)
on 2013-02-12 16:48
Keith B. wrote in post #1096475:
> Nicole -
>
> My JAVA_HOME is set to:
>
>>echo $JAVA_HOME
> /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
>
> With JAVA_HOME correctly set, you should be able to do this:
>
>>$JAVA_HOME/bin/java -version
> java version "1.6.0_37"
> Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
> Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
>
> Could you try changing your JAVA_HOME variable?
>
> - Keith
>
> ---
> Keith R. Bennett
> http://about.me/keithrbennett

OK so I made the changes as you stated:

This is what I have in my .bash_profile

export 
JAVA_HOME='/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home'
export PATH=$PATH:$JAVA_HOME/bin


ts-spare03:bin TargetSpot0054$ which java
/usr/bin/java

So I go in that directory and do this:
ts-spare03:bin TargetSpot0054$ ls -l java
lrwxr-xr-x  1 root  wheel  74 Sep 12 13:49 java -> 
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

So it's not pointing to the java path that is in my .bash_profile

When I do this:
ts-spare03:~ TargetSpot0054$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

That's the old entry that I had in my .bash_profile. I'm not sure why 
it's not picking up the current one.

ts-spare03:etc TargetSpot0054$ $JAVA_HOME/bin/java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)


I did source .bash_profile, I restarted my computer.  I don't know what 
else to do.
Posted by Keith B. (keith_b)
on 2013-02-12 17:13
(Received via mailing list)
Nicole -

In cases like this where I want to specify a non default path, I usually 
put the override path at the beginning of PATH rather than the end of 
it.  So I'd try instead:

export PATH=$JAVA_HOME/bin:$PATH

- Keith
Posted by kristian (Guest)
on 2013-02-12 17:17
(Received via mailing list)
I would get rid of some players like rvm and see if I get it to work
with that. I personally use mostly

$ java -jar jruby-complete-1.7.2.jar

to execute jruby (since these jar just lay around in my local maven
repository). and ubuntu does not set JAVA_HOME which is not needed
when you are to call java. i.e. get the jar from
http://repo1.maven.org/maven2/org/jruby/jruby-complete/1.7.2 and try

$ java -jar jruby-complete-1.7.2.jar -e 'puts require "java"; puts
JRUBY_VERSION'

maybe that is a starting point :)

- Christian
Posted by Nicole Villette (nvillette)
on 2013-02-12 17:55
Keith B. wrote in post #1096490:
> Nicole -
>
> In cases like this where I want to specify a non default path, I usually
> put the override path at the beginning of PATH rather than the end of
> it.  So I'd try instead:
>
> export PATH=$JAVA_HOME/bin:$PATH
>
> - Keith

Thanks Keith, I tried that...still no luck..might have to scrap using 
jruby.
Posted by Keith B. (keith_b)
on 2013-02-12 17:55
(Received via mailing list)
Christian -

That may be a good test for the configuration option, but for general 
use, there are advantages to using rvm.  Mainly that you can use the 
same commands that you would use with MRI ruby -- rake, gem, rails, 
ruby, etcand that you can easily manage multiple versions of JRuby. 
Also that all your gems, etc., are in one place -- ~/.rvm.

It's a matter of personal preference, of course, and the way you 
describe is fine if you like it that way.

- Keith
Posted by Nicole Villette (nvillette)
on 2013-02-12 17:56
kristian wrote in post #1096492:
> I would get rid of some players like rvm and see if I get it to work
> with that. I personally use mostly
>
> $ java -jar jruby-complete-1.7.2.jar
>
> to execute jruby (since these jar just lay around in my local maven
> repository). and ubuntu does not set JAVA_HOME which is not needed
> when you are to call java. i.e. get the jar from
> http://repo1.maven.org/maven2/org/jruby/jruby-complete/1.7.2 and try
>
> $ java -jar jruby-complete-1.7.2.jar -e 'puts require "java"; puts
> JRUBY_VERSION'
>
> maybe that is a starting point :)
>
> - Christian

Thanks...I am going to remove it and if things don't work I will also 
remover jruby...this has been a nightmare.
Posted by John Axel Eriksson (Guest)
on 2013-02-12 18:10
(Received via mailing list)
Hey Nicole! Sorry you've had so much trouble.

I thought I'd chime in with what I do. I use rbenv but that's pretty
similar to rvm. Anyway I never actually set the $PATH. It's not needed
on a Mac at least if you've installed java in the default location
(eg. /Library/Java/JavaVirtualMachines).

I'd suggest you try this:

1. Remove all the settings concerning $JAVA_HOME from your $PATH
2. In your bash profile just do 'export 
JAVA_HOME=`/usr/libexec/java_home`'

So basically just:

export JAVA_HOME=`/usr/libexec/java_home`

Then, in a terminal, try typing "java -version" - you should get some
version output
Try switching to jruby using rvm, then try "ruby -v" - you should see
some version info and the fact that it's jruby that's running

If both of above are successful you should also be able to write a
simple ruby-script which does 'require "java"'.

Another tip, just to see that you're actually running jruby (and not
some other ruby vm) is:

ruby -e "puts RUBY_DESCRIPTION"

That should mention jruby.
Posted by Jon Forums (jonm)
on 2013-02-12 18:18
(Received via mailing list)
> > In cases like this where I want to specify a non default path, I usually
> > put the override path at the beginning of PATH rather than the end of
> > it.  So I'd try instead:
> >
> > export PATH=$JAVA_HOME/bin:$PATH
> >
> > - Keith
>
> Thanks Keith, I tried that...still no luck..might have to scrap using
> jruby.

Try writing a `minimal_env.sh` that removes everything but the 
essentials so you can quickly iterate and build up PATH and other env 
vars until you find the conflict.

Jon

---
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums
Posted by Nicole Villette (nvillette)
on 2013-02-12 18:28
Jon Forums wrote in post #1096506:
>> > In cases like this where I want to specify a non default path, I usually
>> > put the override path at the beginning of PATH rather than the end of
>> > it.  So I'd try instead:
>> >
>> > export PATH=$JAVA_HOME/bin:$PATH
>> >
>> > - Keith
>>
>> Thanks Keith, I tried that...still no luck..might have to scrap using
>> jruby.
>
> Try writing a `minimal_env.sh` that removes everything but the
> essentials so you can quickly iterate and build up PATH and other env
> vars until you find the conflict.
>
> Jon
>
> ---
> Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
> http://thecodeshop.github.com | http://jonforums.github.com/
> twitter: @jonforums

I have no experience with that so I don't want to screw up things more 
than they are....I just can't figure out why it's complaining about 
files that I can clearly find in the paths that are set in the 
.bash_profile.
Posted by Robin McKay (robin2)
on 2013-02-12 19:00
If I was in your shoes I would start over by removing JRuby altogether.

All I need on my path to get Java to work is /bin:/usr/bin and I think
the
same is true for your system because you get the same answer to "which
java" as I get.

I have always found JRuby exceptionally easy to use without RVM. (RVM is
essential for MRI Ruby). RVM is installed on my PC but I haven't used it
for ages. JRuby works fine "in parallel" with it but without using RVM.

I suggest the following steps.

Create a project directory (say myJRtest)
Download the JRuby binary (jruby-bin-1.7.2.zip) save it somewhere safe
and extract it into myJRtest

You will then have a directory structure like this
      myJRtest
         jruby-1.7.2
            bin
            docs
            etc.....

In the directory myRJtest create a shell-script (call it
LocalTerminal.sh) with the following contents which will create the
minimal necessary PATH
  #!/bin/bash

     x-terminal-emulator -e bash -c "
     export PATH=/bin:/usr/bin:$PWD/jruby-1.7.0/bin;

     /bin/bash"

Make the shell-script executable.

When you double-click the shell-script it should open a terminal at the
directory myJRtest and you should be able to do java -version   jruby -v
and everything else.

Check what's in your path with echo $PATH - it should only be what is
exported in the shell-script. On my PC I had to temporarily rename
/home/robin/.bashrc so it wasn't used.

All this should ensure that there is nothing getting in the way of
JRuby. If it works (and I would be surprised if it doesn't) it should
provide a starting point for further trouble shooting.

I always use this method to run JRuby but my regular PATH command is
     export PATH=$PWD/jruby-1.7.0/bin:$PATH;
which retains the other elements of my PATH

...Robin
Posted by John Axel Eriksson (Guest)
on 2013-02-12 19:04
(Received via mailing list)
Not sure why this is, but I actually set everything through .profile 
(not .bash_profile). Otoh if you've verified that java is reachable on 
from the
shell I don't see why there should be trouble.

Does both "java -v" and "ruby -v" return the values you'd expect?

12 feb 2013 kl. 18:28 skrev Nicole Villette <lists@ruby-forum.com>:
Posted by Keith B. (keith_b)
on 2013-02-12 19:21
(Received via mailing list)
John -

> 2. In your bash profile just do 'export JAVA_HOME=`/usr/libexec/java_home`'

This is what I see about that filespec:

[0] 13:09 mac13 /usr/libexec
>cd java_home
cd: not a directory: java_home

[1] 13:10 mac13 /usr/libexec
>ls -l java_home
lrwxr-xr-x  1 root  wheel  79 Nov 14 15:15 java_home -> 
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home

So java_home is apparently a command, and not suitable as a value for 
JAVA_HOME.

Also, to get the Java version, it's "java -version" (see other message).

- Keith
Posted by Keith B. (keith_b)
on 2013-02-12 19:43
(Received via mailing list)
Regarding the difficulties here, I'd like to offer my opinion that it is 
not JRuby but Mac OS that presents the obstacles.

Or, otherwise put, both JRuby and MRI Ruby are much simpler to configure 
in Linux than in Mac OS.  In Mac OS, I've had problems with MRI Ruby and 
its native extensions needing a different compiler from the XCode 
installation's.  I got that to work, and now brew doctor reports 
problems due, I think, to those modifications.

Ironic, isn't it -- Mac OS is supposed to be easier to use.  In many 
ways it is, but when it comes to development related things like this, I 
find Linux much simpler.  Maybe that's unfair because I know Linux 
better than Mac OS, I don't know.

- Keith
Posted by John Axel Eriksson (Guest)
on 2013-02-12 19:46
(Received via mailing list)
Exactly - it's a command and that was how I used it in my example. I'm 
setting JAVA_HOME to the return value.

12 feb 2013 kl. 19:18 skrev Keith Bennett <keithrbennett@gmail.com>:
Posted by Keith B. (keith_b)
on 2013-02-12 19:49
(Received via mailing list)
I see, you're right, sorry.

- Keith
Posted by Nicole Villette (nvillette)
on 2013-02-12 20:17
John Axel Eriksson wrote in post #1096513:
> Not sure why this is, but I actually set everything through .profile
> (not .bash_profile). Otoh if you've verified that java is reachable on
> from the
> shell I don't see why there should be trouble.
>
> Does both "java -v" and "ruby -v" return the values you'd expect?
>
> 12 feb 2013 kl. 18:28 skrev Nicole Villette <lists@ruby-forum.com>:

John,

Yes "java -v" and "ruby -v" return the values you'd expect. I will try 
putting in .profile and see what happens..thx.
Posted by kristian (Guest)
on 2013-02-13 05:04
(Received via mailing list)
On Tue, Feb 12, 2013 at 10:22 PM, Keith Bennett 
<keithrbennett@gmail.com> wrote:
> Christian -
>
> That may be a good test for the configuration option, but for general use, there 
are advantages to using rvm.  Mainly that you can use the same commands that you 
would use with MRI ruby -- rake, gem, rails, ruby, etc…and that you can easily 
manage multiple versions of JRuby.  Also that all your gems, etc., are in one 
place -- ~/.rvm.
>

 do use rbenv occasionally. there my gems stay where they are
~/.gem/ruby/1.8, ~/.gem/ruby/1.9 ~/.gem/jruby/1.8, etc so gem itself
has a bulit in feature to separate gems on a per ruby level:
user-install

then using bundler helps avoiding gem version conflicts.

on top of that rbenv is designed to have minimal dependency or impact
on the environment. that is most probably the debian people suggest to
use rbenv and even never mention rvm (which has some issue the way it
integrates with environment). once I wanted to debug a rubygems with
rvm and I just gave up because I did not find anything anymore.

> It's a matter of personal preference, of course, and the way you describe is 
fine if you like it that way.
>

well, mostly I use jruby within a java program, and the launcher is
mainly MRI which starts java (MRI is just so much faster for the
command line). actually the last project I used a simple script to
generate a load_path.rb file with the help of bundler, which I use to
startup my rackup and feels faster the startup (and it is really
faster).

rvm is not the only one there is rbenv or less featured ruby-switch
from debian-testing
bundler is not the only one, there is isolate or maybe others

and as you say it is a matter of preference and there are popular
solutions and unpopular solutions :)

- Christian
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.