I have a vendor product with Java APIs that I need to write against and would like to use Ruby.
Does anyone have an opinion on the most reliable way to interact with Java from Ruby? I've seen some different projects, but can't tell if there is any major difference between how they are implemented or which are actively maintained.
Jean-Claude Arbaut wrote: > On 21/06/2005 15:12, Wayne Pierce wrote:
>> I have a vendor product with Java APIs that I need to write against >> and would like to use Ruby.
>> Does anyone have an opinion on the most reliable way to interact with >> Java from Ruby? I've seen some different projects, but can't tell if >> there is any major difference between how they are implemented or >> which are actively maintained.
> Seems ugly to me, but anyway...
+1
I'd use plain old Java. That'll be much more hassle free and Java isn't too bad IMHO.
> Maybe you will be able to use C or > C++ as a common "glue code". There is also a program called SWIG, > used to make Java, Ruby, Python, etc... work with C.
A third language in between - even uglier. But probably the only workable way.
On 6/21/05, Wayne Pierce <shalo...@gmail.com> wrote:
> I have a vendor product with Java APIs that I need to write against > and would like to use Ruby.
> Does anyone have an opinion on the most reliable way to interact with > Java from Ruby? I've seen some different projects, but can't tell if > there is any major difference between how they are implemented or > which are actively maintained.
> Thanks,
> Wayne
Two main options: RJB [1], and JRuby [2].
RJB (RubyJava Bridge) is an extension to the standard Ruby interpreter that lets you communicate with a Java VM via JNI. It works pretty well, but can be a bit 'low level' sometimes, due to the nature of its implementation. IE, sometimes you need to know how to construct java method signatures and such (not a big deal)
JRuby is a complete Ruby interpreter written in Java, so all your Ruby code runs in the JVM. This has advantages that the classes can have a tighter relationship, however the implementation is currently a little slow, and partially incomplete. Also, you lose the ability to use Ruby libraries and extensions written in C.
I've used RJB for a project in order to use the JasperReports library, and had pretty decent success. It can be difficult to do proper error handling, because you have both Ruby errors and Java exceptions to deal with. But it is certainly feasible.
It works best when you simply want to call some java code from ruby, and get the result. When you start wanting to have ruby classes inherit from java classes, and have java callback to ruby which calls back to java, it can get messy. Just try to keep it as simple as possible.
On Tue, 21 Jun 2005, Wayne Pierce wrote: > I have a vendor product with Java APIs that I need to write against > and would like to use Ruby.
> Does anyone have an opinion on the most reliable way to interact with > Java from Ruby? I've seen some different projects, but can't tell if > there is any major difference between how they are implemented or > which are actively maintained.
> Thanks,
> Wayne
why not soap objects on bound only to localhost?
-a -- =========================================================================== ==== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso =========================================================================== ====
On Tuesday 21 June 2005 07:45, Robert Klemme wrote:
> Jean-Claude Arbaut wrote: > > On 21/06/2005 15:12, Wayne Pierce wrote: > >> I have a vendor product with Java APIs that I need to write against > >> and would like to use Ruby.
> I'd use plain old Java. That'll be much more hassle free and Java isn't > too bad IMHO.
Both of these are built on the JVM and use the JRE. With all respect to Ruby, I have used both when in a Java environment rather than force Ruby into a place where it is best not to go.
Wayne Pierce wrote: > I have a vendor product with Java APIs that I need to write against > and would like to use Ruby.
> Does anyone have an opinion on the most reliable way to interact with > Java from Ruby? I've seen some different projects, but can't tell if > there is any major difference between how they are implemented or > which are actively maintained.
Here are some ways to interact with Java from Ruby, though I can't say which is the most stable:
Personally, I'd just use Java, or a more Java-compatible scripting language like Beanshell (http://beanshell.org) or Groovy (http://groovy.codehaus.org/). I like Ruby, but I don't see the point of jumping through hoops to use it for everything unless you need to integrate some existing Ruby and Java code.
It could get very ugly, but it may be saner in the long run for this organization.
I had considered using POJ, but want to limit the number of languages in use here. So far I have programs in Ruby, Python, shell (/bin/sh) and sed scripts. I have also inherited some Perl, Tcl and may soon receive C# and PHP code (I was able to turn away the VB).
I understand enough about each of the languages to work with the programs, which is why they come to me when the other person leaves. However if I ever leave there is nobody here that can pick apart all of the different languages; I'd rather not add another one to the mix (Java) if it can be prevented.
For this program I only need to call a function passing in two parameters from the API. From what I read concerning some of the suggestions it should be doable and shouldn't be too difficult.
> On Tuesday 21 June 2005 07:45, Robert Klemme wrote: >> Jean-Claude Arbaut wrote: >> > On 21/06/2005 15:12, Wayne Pierce wrote: >> >> I have a vendor product with Java APIs that I need to write against >> >> and would like to use Ruby.
>> I'd use plain old Java. That'll be much more hassle free and Java isn't >> too bad IMHO.
> Both of these are built on the JVM and use the JRE. With all respect to > Ruby, > I have used both when in a Java environment rather than force Ruby into a > place where it is best not to go.
That's a good suggestion! Then we should mention groovy also which has some similarities with Ruby. However, the last time I looked at it it was still immature and also terribly slow...
> I have a vendor product with Java APIs that I need to write against > and would like to use Ruby.
> Does anyone have an opinion on the most reliable way to interact with > Java from Ruby? I've seen some different projects, but can't tell if > there is any major difference between how they are implemented or > which are actively maintained.
I have another implementation Java-Ruby bridge that is written in pure Java and Ruby.
This bridge is implemented by Javassist and xmlrpc communication. Javassist is bytecode engineering tool. I used xmlrpc to connect java and ruby. Although the communication is very slow, the bridge can establish connection on the many environment.
The YAJB is designed for achievement of following goals:
* easy to use (at least for me, on cygwin/windows XP) * allowing simple and complete GUI code as we write in Java * writing implementation of Java interfaces and any class in Ruby.
I wrote the code for my own purpose, analyzing numerical data and visualizing it with my plot library, not general use. So I'm sorry if you meet troubles. (I'm not sure using gem or setup.rb...)
Here is the sample YAJB code, handling modal JDialog: