开发者

how can i call a java class in ruby

How can i call a java class in 开发者_开发百科ruby?


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


try this Java/Ruby Bridge:

Link

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜