Non-Java user; using Java Classes in JRuby

Although I’m by no means the worlds best coder I’ve managed to get (with
the help of several people on here!) JRuby + JDBC and JRuby-LDAP to do
almost everything I want now. However I’m looking to replace some legacy
Python code that uses the Spread messaging system to synchronise jobs on
various different systems. As the Ruby Spread client relies on a C
component I’m trying to use the java library instead.

I’ve built the spread jar and it’s installed in my CLASSPATH, but I’m
struggling a little to figure out how to import the classes (the spread
documentation just shows an 'import spread.’ which doesn’t seem to work
in JRuby; I think the actual path is java.spread.
) and setup a new
connection. The spread tutorial lists the following code to create a new
connection:

import spread.*
SpreadConnection connection = new SpreadConnection();
connection.connect(address, 0, “privatename”, false, false);
… do stuff…
connection.disconnect

I assume I will need to do something like:

require “java”
import java.spread.*
connection = java.spread.SpreadConnection()
connection.connect(,)

connection.disconnect

Other than JDBC, for which I was able to find some really nice examples
for, I haven’t needed to touch the Java functionality so far - so it’s
unexplored territory for me! Does anyone have a simple example of how I
can make the spread classes available so that I can setup a new
connection?

Cheers

John

Unix & Web Infrastructure Management
Faculty of Medical Sciences Computing
University of Newcastle

Email : [email protected]
Web: http://www.ncl.ac.uk/medev


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

A bit of looking back through the mail archive and I think I answered my
own question; the following seems to run without issue:

require “java”
import “spread.SpreadConnection”
import “spread.SpreadMessage”
begin
sConnection = SpreadConnection.new
sConnection.connect(nil, 4803, “conn_name”, false, false)

actual stuff goes here

sConnection.disconnect
rescue
puts “sendSpread - Connection failure”
end

I’ve a bit of head scratching to do with regard to the actual message
construction - it’s not quite as simple as the Python API where you can
just pass a block of text to send… but I’m sure I’ll figure that bit
out, at least I can now actually connect to our existing spread groups
that we have running.

John

Unix & Web Infrastructure Management
Faculty of Medical Sciences Computing
University of Newcastle
Email : [email protected]
Web: http://www.ncl.ac.uk/medev

various different systems. As the Ruby Spread client relies on a C
SpreadConnection connection = new SpreadConnection();

John
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

You may need to setup your classpath correctly. If you want the ruby
script to be executable then I oftern do this…

[“#{File.dirname FILE}/…/build/”, “#{File.dirname
FILE}/…/lib/”].concat(Dir[“#{File.dirname
FILE}/…/lib/*.jar”]).each { |jar| $CLASSPATH << jar }

The idea is to update $CLASSPATH prior to your imports.

On Mon, Oct 13, 2008 at 7:54 AM, John S.
[email protected] wrote:

rescue
Email : [email protected]

the help of several people on here!) JRuby + JDBC and JRuby-LDAP to do
connection:
import java.spread.*

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email