rjava

RJava enables Ruby to use Java classes in ruby programs using ruby-like syntax.

License

Probably LGPL or GPL.

Requirements

Download

Examples

Hello World!

This simple program lets the JVM print "Hello World!" on its console window.

require "java"

include JAVA

JVM.start_tcp().import("java.lang.System").out.println("Hello World!")

JFrame

This sample opens a swing frame containing a text label. It shows most concepts that are currently supported: Access to static methods and variables (or constants), constructing objects, calling methods.
require "java"

include JAVA

def create_pane
	pane = @jvm.new("javax.swing.JPanel", @jvm.new("java.awt.GridBagLayout"))
	gbc = @jvm.new("java.awt.GridBagConstraints")
	label = @jvm.new("javax.swing.JLabel", "Some Text")
	gbc.fill = gbc.jclass.BOTH
	pane.add(label, gbc)
	pane
end

@jvm = JVM.start_tcp
jframe_class = @jvm.import("javax.swing.JFrame")
jframe = jframe_class.new("Ruby-Swing-Sample")
jframe.setSize(300, 200)
jframe.setDefaultCloseOperation(jframe_class.DISPOSE_ON_CLOSE)
jframe.setContentPane(create_pane)
jframe.setVisible(true)

Limitations

The current implementation is an early preview with several limitations:

Background

The idea for this project was born during the First European Ruby Conference in Karlsruhe (Germany) on June 21th - 22th. I do the development in my spare time when my wife and my new born son let me do. Therefore my progress is very slow.

Contact

For installation problems, critique and suggestions please feel free to send me an email at rjava@spricom.com. Due to lack of time, I might not be able to answer each mail individually.

Author

Hans Jörg Hessmann, 19.10.2003