Rb script not running

Hi everybody,

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

require ‘java’
JFrame = javax.swing.JFrame
JOptionPane = javax.swing.JOptionPane
frame = JFrame.new
frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
frame.pack

def showMessage
return “This is output from a Ruby function!”
end

JOptionPane.showMessageDialog(frame, showMessage);

</TEST.RB>

Charles -

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 #!.

Good luck,

  • Keith

Thanks for the response!

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).

Thanks again!

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!

Charles,

On 11/19/12 7:14 PM, Charles R. wrote:

http://www.ruby-forum.com/attachment/7885/Screen_Shot_2012-11-19_at_7.11.20_PM.png
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).

  • George


I’m running Mountain Lion (10.8.2).

Thanks!

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?


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan

Charles -

The JRuby directory you inserted into test.rb in the shebang line is not
the same directory as the one you ran on the command line:

#!/usr/local/jruby-1.7.0/bin/jruby

vs.

/usr/local/jruby/bin/jruby test.rb

Do you have a /usr/local/jruby-1.7.0/bin/ directory? What happens if
you do this?:

ls -l /usr/local/jruby-1.7.0/bin/jruby

Also, another way to make the script executable is instead of specifying
an absolute directory, you can do this:

#!/usr/bin/env jruby

Can you try that instead and see if it works?

  • Keith

Keith R. Bennett
http://about.me/keithrbennett

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:

http://www.randomactsofsentience.com/2012/10/os-x-jruby-170-require-command-not-found.html

Might help.

Kimbo

On 21/11/2012, at 9:43 AM, Charles R. wrote:


Posted via http://www.ruby-forum.com/.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Ms Kimberley Scott
Senior Software Engineer
http://www.randomactsofsentience.com/
http://www.facebook.com/kimberley.scott.14

I’ll give that a shot - thanks!

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.

| Privacy Policy | Terms of Service | Remote Ruby Jobs