[this message was first rejected by SpamAssassin ]
More information at http://www.thekode.net/ruby/rjni
rjni: Java binding for Ruby through JNI
Copyright (c) 2003 Mauricio Julio Fernández Pradier
WARNING: This is a technology preview. The software is not even alpha
quality at the moment and is not meant to be used yet. It is only
provided to present the techniques employed and (hopefully) to
accelerate the development.
Feedback: please don’t hesitate to contact me to criticize, suggest new
features or help with the development
License
For the time being, the same as Ruby. Might switch to LGPL in the future.
Status
* The APIs are quickly stabilizing.
* The base layer still needs some work and further testing.
* Several low-level issues remain to be solved.
* The higher-level APIs have yet to be documented and tested rigorously.
What is rjni?
rjni exposes the Java Native Interface to Ruby. This allows the programmer
to instantiate Java objects, manipulate them, define Java classes, etc…
from Ruby.
Note that rjni is not meant to embed Ruby into Java, although it can be
used to ease integration in that case.
Building
This technology preview is meant to illustrate the possibilities offered
by rjni. It is by no means a usable library yet. The build process is
quite tricky, as it involves linking against the Java libraries and is
therefore highly system-dependent.
The steps are:
1. creating the Makefile. This is done by executing
ruby extconf.rb
–with-jsdk-include=/usr/local/java/j2sdk1.4.1/include/
–with-jsdk-lib=/usr/local/java/j2sdk1.4.1/jre/lib/i386/
–with-jsdk-so-include=/usr/local/java/j2sdk1.4.1/include/linux/
You have to replace the paths above by the appropriate values for your
local Java installation. Note that rjni has been tested with Blackdown
1.4.1, and, although it should be possible to build it with other
JSDKs, compilation and/or linking might fail unless you get the above
options right and/or modify extconf.rb itself (or end up modifying the
Makefile by hand :)
2. Compiling
make
3. You can now run the tests:
./tc_all.sh
You will notice a short pause after the execution of the script. This
is normal and expected at the moment.
4. High-level API demo:
./test_reflect.sh
Problems
Compilation
Were you to experience difficulties when compiling, you'd have to make
sure that the appropriate -rpath and/or -L options are passed to gcc.
Execution
Sometimes ld.so will be unable to resolve symbols at runtime; you will
then need to set the LD_LIBRARY_PATH environment variable
to some sensible value.
APIs
RJNI will have at least 3 APIs:
* RJNI: a low-level straight-forward mapping of the Java Native
Interface to Ruby. All operations on Java objects and classes are
ultimately performed through this layer.
* RJNI::Java: a direct conversion of java.lang.reflect and
associated classes to Ruby. It is built upon RJNI.
* RJNI::Reflect: magic reflection of Java objects to Ruby, such
that they can seemingly be manipulated exactly like Ruby objects.
This involves automatic method dispatching, singleton class
abstraction (static methods become singleton methods of the class
object), some automatic type conversions, attribute setters and
getters, etc.
···
–
_ _
__ __ | | ___ _ __ ___ __ _ _ __
'_ \ /| __/ __| '_
_ \ / ` | ’ \
) | (| | |__ \ | | | | | (| | | | |
.__/ _,|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com
Linux: Where Don’t We Want To Go Today?
– Submitted by Pancrazio De Mauro, paraphrasing some well-known sales talk