Eric,
I think most of your steps are correct. I suspect that if you are
including the JAR on the JVM CLASSPATH, you would not need to require the
JAR individually (JRuby can resolve the class using normal Java
classloading).
3 and 4 are substitutes for each other. Use one or the other, or
both. If you want to avoid namespace pollution, you may want to use Java::
prefix (or there is another form that only imports into a specific Ruby
namespace, but I don't remember off my head).
If your type is Foo, you don't need to include_class Foo. JRuby uses
reflection and can figure out the type by itself. You only need to include
Java classes if you need to refer to them by name explicitly.
Peter
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 22, 2007 7:10 PM
To: jruby-dev
Subject: [jruby-dev] Working with Java classes in JRuby
http://java.sun.com/developer/technicalArticles/scripting/jruby/
http://www.headius.com/jrubywiki/index.php/Calling_Java_from_JRuby
After examining those writeups and doing a lot of experimenting,
I've been able to make 3rd party Java classes accessible by doing
the following:
1. Putting the JAR files in the CLASSPATH
(or $RUBY_HOME/lib)
AND 2. Requiring each jar individually
AND 3. Doing an include_class on each class I want to access,
using a fully qualified package name.
AND 4. Using the Java:: prefix when naming one of classes in
the code.
Comments:
* Doing steps 1, 3, and 4 didn't seem to work until I added step 2.
* I haven't tried steps 1 and 2 by themselves.
* I suspect that either step 3 or 4 is needed, but both are
not required. So if this method returns a Foo object:
x = Java::some.package.MyClass.staticGetMethod()
then:
include_class is probably /not/ necessary for MyClass
include_class probably /is/ necessary for Foo
Is that substantially correct, or are parts of it overkill?
--
Eric Armstrong, Document Systems Architect, Sun Microsystems
http://blogs.sun.com/coolstuff
http://www.artima.com/weblogs/index.jsp?blogger=cooltools
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email