From: SAKURAI Masashi Date: 2005-06-22T07:38:50+09:00 Subject: Re: Ruby and Java Hi, > 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. YAJB http://www.cmt.phys.kyushu-u.ac.jp/~M.Sakurai/cgi-bin/fw/wiki.cgi?page=YAJB 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: ============================= #!/usr/bin/ruby require 'yajb/jbridge' include JavaBridge jimport "java.awt.*" jimport "java.awt.event.*" jimport "javax.swing.*" label = jnew :JLabel, "Hello World!" button = jnew :JButton, "open!" action = jextend :ActionListener button.addActionListener(action) panel = jnew :JPanel, jnew(:GridLayout,2,1) panel.add(label) panel.add(button) frame = jnew :JFrame, "JDialog DEMO" frame.getContentPane.add(panel) frame.pack class << action def init(f,l) @frame = f @label = l end def actionPerformed(event) dlg = jnew :JDialog, @frame, "Modal Dialog!", true text = jnew :JTextField,12 okbtn = jnew :JButton,"OK" action = jextend :ActionListener class << action def init(d,t,l) @dlg = d; @text = t; @label = l end def actionPerformed(e) @label.setText(@text.getText()) @dlg.dispose() end end action.init(dlg,text,@label) okbtn.addActionListener(action) panel = jnew :JPanel panel.add(text) panel.add(okbtn) dlg.getContentPane.add(panel) dlg.pack dlg.show end end action.init(frame,label) wc = jextend :WindowAdapter class << wc def windowClosing(e) break_bridge wakeup_thread end end frame.addWindowListener(wc) frame.show() stop_thread =======================