tags:

views:

188

answers:

3

Hi all

If I implement a class in ruby and compile it with jrubyc than it is not possible to call it from a java class directly if I start it with java. If I see this right I have to use org.jruby.embed... to implement a wrapper wich takes a class name and a metod to call my ruby class.

Do I have to do this also if I start the application with jruby? In my current project I start java workflow engine completely with jruby. The workflow has to call a method in a ruby class which he cant find.

Maybe easier to understand:

      [ruby_class]   <-----has to call----.
                                          |
jruby [ruby_start_script] --starts--> [java wfe]
A: 

I don't know if i understood, but to require your code, you just have to require it and make it sure that it its in your JAVA PATH or APP PATH. For example, in your jruby script you can do it:

require 'java'
java_import java.lang.System
version = System.getProperties["java.runtime.version"]

You can call as well java methods like:

 java.lang.System.currentTimeMillis

I would say that you make your class work with a java app, then you should put it in your app path, do a require 'java' and java_import your.class.here

VP
I'm able to call Java methods but i'm unable to let the java workflow engine call my ruby method. I'm not sure that this is the general - "You can't call jruby from java without a hack." - because I run the java code inside jruby.Complicated to explain...
r2
A: 

If I implement a class in ruby and compile it with jrubyc than it is not possible to call it from a java class directly if I start it with java.

Not sure if I understand the question entirely but if you are asking if you can call a Jruby method from a Java class using jrubyc, it is possible. Take a look at this blog post which shows how to call a JRuby method from Java.

tommy chheng
A: 

IIRC, this is one of the newest integrations to JRuby, and may be subject to change. It seems to be possible as described in this post, albeit warns not being very efficient.

Chubas