Wednesday, October 8, 2008

Ruby - Trying it again

This issue has been resolved --> Here



Still issues running JRuby with NetBeans and Windows. I've upgraded NetBeans from version 6.1 to 6.5 beta to see if the latest and greatest fixes my issues.

I find this especially irritating given the amount of hype around the framework as a whole. (IntelliJ demo, Netbeans 10-minute JRuby Blog).

It seems most of the issues lie in platform-specific gems, and net-ssh seems to be written for use with PuTTY's pageant, which requires "native interfacing" or "native extensions". Is it possible?

Well, I'm starting off trying to ssh into a remote device using Ruby samples from this script inside the NetBeans IDE.

Upon first try, I got the following:
failed to load dl/import
Using this tutorial from Juan Pablo I was able to modify:
C:\Program Files\NetBeans 6.5 Beta\ruby2\jruby-1.1.3\lib\ruby\gems\1.8\gems\net-ssh-2.0.4\lib\net\ssh\authentication\pageant.rb
and

C:\Program Files\NetBeans 6.5 Beta\ruby2\jruby-1.1.3\lib\ruby\gems\1.8\gems\net-ssh-2.0.4\lib\net\ssh\known_hosts.rb

I get a new message:
The system cannot find the path specified
I looked for debug options with the JRuby command, and found them:
C:\Program Files\NetBeans 6.5 Beta\ruby2\jruby-1.1.3\bin\jruby.bat -d C:\path_to_my\main.rb

And now I get the following:
Exception `LoadError' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34 - no such file to load -- openssl
C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/transport/state.rb:85 warning: Useless use of a variable in void context.
Exception `LoadError' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34 - no such file to load -- highline
Exception `LoadError' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34 - no such file to load -- termios
SSH Starting...

Exception `Net::SSH::Exception' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/transport/algorithms.rb:296 - could not settle on language_client algorithm
Exception `Net::SSH::Exception' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/transport/algorithms.rb:296 - could not settle on language_server algorithm
The system cannot find the path specified
Exception `Net::SSH::Authentication::AgentNotAvailable' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/authentication/agent.rb:74 - private method `open' called for Net::SSH::Authent
ication::Pageant::Socket:Class
Exception `Net::SSH::ChannelRequestFailed' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/gems/1.8/gems/net-ssh-2.0.4/lib/net/ssh/connection/channel.rb:544 - Net::SSH::ChannelRequestFailed

Installing hiline yeilds this new error:

Exception `LoadError' at C:/Program Files/NetBeans 6.5 Beta/ruby2/jruby-1.1.3/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:34 - no such file to load -- Win32API
I now have hiline, termios, net-ssh, open-ssl and not much more luck....

I tried to install the win32-api but JRuby gem install returns with error "Jruby does not support native extensions", which makes perfect sense!

When finished, I'll have a detailed write-up for this. Automated ssh, sftp, scp through Ruby scripts would be a really nice addition to a Java application, despite the platform.

Any help is welcome.

Cheers.

-Tres


3 comments:

ckutler said...

I find it useful to download JRuby into a folder that is not burried deep inside the NetBeans installation. Then use the Platforms manager to add that to NetBeans. It makes your gems repository more permanent, should you upgrade NetBeans, and it makes it easier to drop to the command line to test out problems with JRuby, such as what you are having.

You are correct that you can't use gems that have native extenstions. See http://kenai.com/projects/jruby/pages/GettingStarted#Installing_and_using_Gems_in_JRuby.

ckutler said...

I am not sure this helps, but JRuby does not bundle SSL support. If you go to the last page of a new rails project wizard, there is a button to install JRuby OpenSSL Support. You can also install using the Gems manager, of course.

Juan Pablo said...

hmm, I did not need either the hiline or Win32 gems to make ssh work. I do think you are missing the jruby-openssl gem tho. Using the Gems manager included in Netbeans (tools->ruby gems) uninstall the the jruby-openssl gem that you have (if any) and then install the jruby-openssl gem latest version (0.3 as of today). However, you will see two jruby-openssl listed, make sure you choose to install the jruby-openssl gem that has its name all lowercase and it's version 0.3.