views:

44

answers:

3

how can i call a java class in ruby

A: 

Hi,

try this Java/Ruby Bridge:

Link

The Bridge itselfs enables you to load java classes into your ruby Code.

bastianneu
+5  A: 

If you use JRuby, you can

require 'java'

and then instantiate a Java class using eg

object = Java::package.package.ClassName.new

and then call methods using

object.method(parameter)

for more information, see Scripting Java libraries with JRuby

Adrian
A: 

Can you wrap, or call, the Java class with another Java class with a main() method reading stdin or command-line arguments ? You can then spawn that as an executable from Ruby, write to stdin and read from stdout.

That may be the simplest answer, bearing in mind it's not the fastest mechanism, or in some cases the most practical. For some scenarios, however, it may be the most pragmatic.

Brian Agnew