BindIt is a tool that allows to build platform-agnostic Ruby wrappers for Java code. The resulting bindings will work both on the JRuby and MRI platforms. On the MRI platform, BindIt uses the Ruby-Java-Bridge (Rjb) to access Java objects.
BindIt is tested on MRI Ruby 1.9.2 and 1.9.3, as well as JRuby 1.6.7.2 and 1.7.1.
gem install bind-it
Usage
- Create a module into which Java classes will be loaded.
- Make sure that module extends
BindIt::Binding
. - Set your configuration options (see examples below).
- Run YourModule.bind to load the default JARs and classes.
- Access loaded Java classes using YourModule::YourClass.
require 'bind-it'
module MyBindings
extend BindIt::Binding
# Arguments to use when initializing the JVM.
self.jvm_args = ['-option1X', '-option2X']
# If set, JVM output is redirected to file.
self.log_file = 'log_file.txt'
# The path in which to look for JAR files.
self.jar_path = '/path/to/jars/'
# Default JAR files to load.
self.default_jars = [
'jar1.jar',
'jar2.jar'
]
# Default namespace to use when loading classes.
self.default_namespace = 'path.to.default'
# Default classes to load under MyBindings.
# Shown are the three different ways of adding
# a class to the default list.
self.default_classes = [
# Will search for class in default_namespace.
['MyClass'],
# Supply a non-default namespace.
['MyClass', 'path.to.namespace']
]
# Load the default JARs and classes.
self.bind
end
obj = MyBindings::MyClass.new
Feel free to fork the project and send me a pull request!