zhessy
zhessy

Reputation: 49

how can i call a java class in ruby

How can i call a java class in ruby?

Upvotes: 4

Views: 2691

Answers (3)

Brian Agnew
Brian Agnew

Reputation: 272277

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.

Upvotes: 1

akuhn
akuhn

Reputation: 27793

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

Upvotes: 8

bastianneu
bastianneu

Reputation: 2069

try this Java/Ruby Bridge:

Link

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

Upvotes: 1

Related Questions