Friday, June 22, 2012

Add Ruby Gems to your Jruby Application

In two way you can add Ruby Gems to your JRuby application.

Case 1: In this case we will take the gems for ssh connections i.e. net-ssh. So what ever the gems you want to add in your application , 1st check the required dependencies for that gems. in this case for net-ssh we required

1)jruby-openssl
2)jruby-pageant

Steps:: Case 1:-

1)download the jruby-complete-XXXX.jar file . check with below link for the respective versions.

http://jruby.org/download

you can create a jruby-complete.jar file from source too.
            a) download the jruby source from http://jruby.org/download
                Ex:-  E:\jruby-src-1.6.7.2.zip

            b) unzip it to any local directory
                 Ex:- unzip  jruby-src-1.6.7.2.zip
                         It will create a directory  jruby-1.6.7.2
            c) download and unzip ant if ant is not on your system http://ant.apache.org/bindownload.cgi
            d) set the ANT_HOME and PATH for the ant.
            e) change current directory  to the unzip jruby source directory
                   cd E:\jruby-1.6.7.2
            f) ant jruby-complete

It will create a jruby-complete.jar file which is same as if you follow to download it from the repository link http://jruby.org/download

Let your final jruby-complete.jar file in E:\jruby\jruby-complete.jar

2)  Let download and get the required gems . use the following command to do so

To get jruby-openssl:

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./jruby-openssl jruby-openssl --no-rdoc --no-ri

To get jruby-pageant:

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./jruby-pageant jruby-pageant --no-rdoc --no-ri

To Get net-ssh :

java -jar jruby-complete-1.6.7.2.jar -S gem install -i ./net-ssh net-ssh --no-rdoc --no-ri

Now you have all the gems in your current directory i.e. E:\jruby

3) Let push these gems to the jruby-complete.jar file

jar uf jruby-complete-1.6.7.2.jar -C jruby-openssl .
jar uf jruby-complete-1.6.7.2.jar -C jruby-pageant .
jar uf jruby-complete-1.6.7.2.jar -C net-ssh .

4)  Lets check if the gems pushed successfully or not

java -jar jruby-complete-1.6.7.2.jar -S gem list

*** LOCAL GEMS ***

bouncy-castle-java (1.5.0146.1)
jruby-openssl (0.7.7)
jruby-pageant (1.1.1 java)
net-ssh (2.5.2)
rake (0.8.7)
sources (0.0.1)

5)  Let's check if the gems are loading through require or not

java -jar jruby-complete-1.6.7.2.jar -S irb

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'net/ssh'
=> true
irb(main):003:0> exit

-------------------------------End of Case 1--------------------------------------------------------------------
NOTE : you can install and push the gems in a single command also , just use them in the same command syntax with space..
--------------------------------------------------------------------------------------------------------------------
WOW that's it . now all your gems in your jar file.


Steps - Case 2:

case 2 is the traditional one.

1) follow the same step no 1 from Case1
2) now you have the jruby-complete.jar file . and your current directory is
     E:\jruby
     create a directory structure E:\jruby\lib\gems\1.8

Note : Here I used the above path for a separate the gems directory . So it is completely depends on you how you manage your path.

3) java -jar jruby-complete.jar -S install jruby-openssl jruby-pageant net-ssh --no-ri --no-rdoc -i lib/gems/1.8

 The above command will install all the required gems described in the command in the defined path . So here you can replace your destination path


4) Set the GEM_PATH

set GEM_PATH=E:\jruby\lib\gems\1.8

In Linux : export GEM_PATH=`pwd`/lib/gems/1.8

5)  Now follow the Steps No 4 and 5 from Case 1 to get the result.

That's It

------------------------------------------End of Case 2--------------------------------------------------

- Khirod







Tuesday, June 19, 2012

rvd: Unable to create transport on UDP port XXXX

2012-06-19 03:22:26 rvd: Unable to create transport on UDP port XXX. Previously created transport specified network as '192.168.XXX.15;192.168.180.255;192.168.XXX.125' which caused the send address for the port to be bound to 192.168.XXX.125, while current transport specifies network as ';;192.168.XXX.51;;' which requests the send address to be bound to 192.168.XXX.51. You cannot associate the same service parameter with two different network parameters.
./tibrvsend: Failed to initialize transport: Arguments conflict




In the above case just change the service port number and accordingly on the listener side. The above error is normal. Here the subnet is different So so the UDP port being reserved by some time . after sometime it will be released automatically.

If you do not want to wait upto release just use another service port . careful if the same port may be used by any other service. So better have a grep to /etc/services with the used port. In the most worst case just restart the RVD.




Example :

./tibrvsend -network ";;192.168.188.51" -service XXXX -daemon tcp:7500 Test.message "Hello World"

Next use
./tibrvsend -network ";;192.168.199.156" -service YYYY -daemon tcp:7500 Test.message "Hello World"

tibrvsend to different subnet

The below example will explain you, how to send the message to different subnet.

Let  a network Bcast Address : 192.168.180.255
                              System IP  : 192.168.180.15
                             Host Name : tiger100
                   RVD service port : 7190


Another Network Bcast Address: 192.168.175.255
                             System IP       :192.168.175.51
                             Host Name     : lion100
                       RVD service port : 5991

Here we are going to send the message from tiger100 to lion100

1) check on both system if rvd process is running or not. It should running . else start rvd on both
    
    ps -ef | grep 'rvd'

2) Start the rvd listener on lion100

./tibrvlisten -service 7190  -daemon tcp:7500 Test.message

3) Now send the message from tiger100

./tibrvsend -network ";;192.168.175.51" -service 7190 -daemon tcp:7500 Test.message "Hello World"

That it... Now you the message at lion100.

Friday, June 1, 2012

File.executable? does not in this environment and will return a dummy value

 warning: executable? does not in this environment and will return a dummy value

I face this warning in java5 when executing command in system("command/shell script"). as the system usually check if the shell script is executable or not.

and java5 is required anyway for my application . So did the below changes to avoid the warning.

Before : system("shell Script")
After : output=`#{command}`