Require -Cannot load such file --java

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

Are you using rvm or such, and calling jruby as ‘ruby’ instead? I
suspect
you are calling a non-jruby somehow.

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 A. [email protected]
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: [email protected]

Hiro A. 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™ 64-Bit
Server VM 1.6.0_35-b10-428-11M3811 [darwin-x86_64]

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

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 V. [email protected]
wrote:


blog: http://blog.enebo.com twitter: tom_enebo
mail: removed_em[email protected]

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

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

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 V. [email protected]
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
[email protected], Michal P. [email protected]
[https://rvm.io/]”
updated: “20 hours 3 minutes 59 seconds ago”

ruby:
interpreter: “No”
version: “java'" date: "Nojava’ 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: "Nojava’ 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/[email protected]/bin/rake”

environment:
PATH:
“/Users/TargetSpot0054/.rvm/gems/jruby-1.7.2/bin:/Users/TargetSpot0054/.rvm/gems/[email protected]/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/[email protected]
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: [email protected]

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™ SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot™ 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

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 `’: uninitialized constant Java
(NameError)

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™ SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot™ 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™ SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot™ 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.

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

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 :slight_smile:

  • Christian

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

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.

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 :slight_smile:

  • Christian

Thanks…I am going to remove it and if things don’t work I will also
remover jruby…this has been a nightmare.

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

Jon F. 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.

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.