Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you call compiled JRuby classes from java?

So I came up with the general idea to write some code in JRuby, then access all the classes via Java. I have no idea if this is at all possible but I wanted to ask anyway. Lets say I have some JRuby code:

class adder
   def addme
      return 22
   end
end

If I compiled this with jrubyc is there any way I could then possibly do something like this in java:

import adder;
class anything {
    void testMethod() 
    {
       adder a = new adder();
       int x = a.addme();
    }
 }

After looking at it now it sort of makes me think that Java will have zero idea what sort of item test addme is going to return so that might not work. I don't know but I wanted to throw it out there anyway.

Thanks

like image 767
Matthew Stopa Avatar asked May 04 '10 22:05

Matthew Stopa


1 Answers

There's actually a new way to do this in JRuby 1.5! Your question is very timely. Here's an example session:

http://gist.github.com/390342

We will hopefully have a blog post detailing this new feature very soon. There's some preliminary docs on the JRuby wiki here:

http://wiki.jruby.org/GeneratingJavaClasses

like image 152
Charles Oliver Nutter Avatar answered Sep 22 '22 01:09

Charles Oliver Nutter