On Mon, Feb 1, 2010 at 11:19 PM, stephanos [email protected] wrote:
Well, I investigated this a little more - here is what I found by using a
decompiler.
PS: Meanwhile the interface ‘IKataSolution’ was changed to a class
‘BaseKataSolution’ with still the same error
######### Decompiled Groovy version #########
public class MyKata extends BaseKataSolution
 implements GroovyObject
OT: Interesting that they have GroovyObject as their equivalent to our
“IRubyObject” interface and stuff it into Groovy classes that extend
other Java classes. This is the same in the new JRuby “real java
class” support.
######### Decompiled JRuby version #########
public class MyKata extends AbstractScript
The classes produced by JRuby are certainly not “real” classes in
JRuby 1.4. On the contrary, they’re just a “bag of methods” bound
entirely at runtime.
Obviously the generated/compiled groovy version does compile to a
‘BaseKataSolution’ type, but the JRuby version does not!
Yes This is known, and has been a limitation of JRuby forever. But
there’s hope ahead!!!
JRuby 1.5 has started to introduce to compile (ahead of time) to
normal Java classes. For any case like this where you have to specify
a class before runtime, you will need the JRuby 1.5 feature (or you
could cobble something together with the ruby2java gem).
Here’s how your example would work in JRuby 1.5
RUBY CODE
java_import org.codingkata.unit.api.BaseKataSolution
class MyKata
java_implements BaseKataSolution
java_signature [] => String
def reply
# your reply code here
end
end
######################
Command line session
$ jrubyc --java my_kata.rb
<generates a .class for the script and a .java and .class for the MyKata
class>
##########################
The resulting class file could then be configured in your Spring
config exactly like the Groovy version!
Now the jruby --java support is a work in progress. I need more peopel
to experiment with it and offer suggestions. But all the logic to
generate this “real” Java class ends up being only a few hundred lines
of Ruby code, in lib/ruby/site_ruby/shared/jruby/compiler.rb. It’s
very simple:
- Reads in the source of the file(s) being compiled
- Processes them for java_ calls (java_import, java_signature, etc),
classes, and methods
- Generates .java source for all classes encountered
- Compiles the Ruby scripts to “bag of methods” .class files and uses
javac to compile the .java sources to .class files
When it’s all done, you have precompiled Ruby code plus all the “real”
Java classes you need!
Maybe you should pull a JRuby 1.5 snapshot and start playing with it?
I really do need help working out the bugs, writing tests, adding
features, and basically making it do what users want it to do.
Charles Oliver N.-4 wrote:
Sorry for the lack of responses on this one…OSGi scares many of us
class MyKata
via Spring DM - Spring throws the exception
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