Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JRuby and Java objects

Please tell me if it is possible to do the following:

  • create an instance of a specific class in Java
  • pass it to JRuby to do something with it
  • continue using the "modified" version in Java

May you provide a small working example?

EDIT: It turns out that embedding was the simplest way to achieve this. More information is available on Embedding JRuby.

like image 945
Geo Avatar asked Nov 20 '08 17:11

Geo


People also ask

Does JRuby need Java?

x, JRuby internally needs to require 'java' so it has already required 'java' by the time your expression is evaluated. So technically it is true that "require 'java'" loads Java interoperability, but since our kernel does this now it is largely a no-op by the time you call it (see return value of the require).

What is JRuby used for?

JRuby is designed to work as a mixed-mode virtual machine for Ruby, where code can be either interpreted directly, just-in-time compiled at runtime to Java bytecode, or ahead-of-time compiled to Java bytecode before execution.


2 Answers

This was the solution I used : Direct JRuby embedding

like image 21
Geo Avatar answered Sep 28 '22 06:09

Geo


Yes it's possible. This page on the JRuby wiki should get you started.

like image 188
digitalsanctum Avatar answered Sep 28 '22 07:09

digitalsanctum