I am very new to JRuby - but it seems awesome - I am able to do a “hello
world” just fine. My rb script is named ‘test.rb’ - it runs fine when I
issue the command ‘jruby ./test.rb’ - and it runs fine when I run
‘/usr/local/jruby-1.7.0/bin/jruby test.rb’ - but when I run ‘./test.rb’
I get the following errors:
./test.rb: line 4: require: command not found
./test.rb: line 5: JFrame: command not found
./test.rb: line 6: JOptionPane: command not found
./test.rb: line 7: frame: command not found
./test.rb: line 8: syntax error near unexpected token JFrame::EXIT_ON_CLOSE' ./test.rb: line 8:frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE) ’
I do have the script appropriately hash-banged, I can’t figure it out -
can anybody point me in the right direction please? My ‘test.rb’ is
below.
Thanks a lot!
<TEST.RB>
#!/usr/local/jruby-1.7.0/bin/jruby #Ruby running in the JVM
It looks like you may have a blank line before the #! line. I think
that has to be the very first line, even if there is no executable
code before it.
If not, I’m still pretty sure it’s your #! line, and has nothing to do
with your ruby script. (The errors you’re seeing are consistent with
the shell thinking that it should interpret the Ruby code itself.) I’d
suggest commenting out all the Ruby stuff and put something simple
there like puts “Hello”, and trying different things with the #!.
I don’t have an extra line above the hash-bang, I just wrote it that way
in my original post. It’s the weirdest thing, I feel like I’m taking
crazy pills! I attached a screenshot if it helps any (the path of jruby
is a bit different on the machine I am using now).
That jruby.rb file is just another “test” script I was playing around
with. I’m stumped - I have no other characters or anything floating
around. Thank you for your help!
What OS are you running? I get similar results on Snow Leopard. I took
out the gui part and just used a printf, and got a shebanged file to
work OK on Linux (headless).
On Mon, Nov 19, 2012 at 4:14 PM, Charles R. [email protected]
wrote:
I don’t have an extra line above the hash-bang, I just wrote it that way
in my original post.
Your script, verbatim other than changing the path in the first line to
match my system’s JRuby install, works fine here (JRuby 1.7.0 on
Mac OS).
However, when I first pasted that path into the file, I inadvertently
duplicated the # at the beginning of the line ( ##!/blah/blah/… ). And
that gave me the exact output you’re seeing.
Also, perhaps irrelevant, what’s that ‘jruby.rb’ file?
I kinda had a similar problem on OS X.
Turned out that the jruby script itself has “env bash” shebang.
Which seemed to muck up the paths due to OS X bash config.
My fix was to change the “#!/opt/jruby-1.7.0/bin/jruby” shebang at the
top of the …/bin/rails, rake etc with:
#!/usr/bin/env jruby
#!/opt/jruby-1.7.0/bin/jruby (for reference)
I wrote a short incomplete post about it here:
Well, I tried #!/usr/bin/env jruby and it worked just fine - but why
wouldn’t the absolute path work - hmmmm…
And the difference in paths for jruby was just the different locations
on my work computer and home computer - I started testing it at work and
then went home, so I had to change paths.
If anybody has any more ideas about why the absolute path isn’t working
I would love to hear them - thanks everybody!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.