Hi Stephanos,
I have the jruby-maven-plugin successfully generating the .java source
during the generate-sources build phase by changing the execution
phase for the jruby-maven-plugin to <phase>generate-sources</phase>
(and make sure generateJava is set to true). Maven then compiles it to
a .class on its own during the compile phase.
The catch I see is that jrubyc generated classes always inherit from
RubyObject which prevents them from inheriting from BaseKataSolution
and since your calling code is trying to cast it to a BaseKataSolution
it's failing on the cast. With JRuby's java_implements keyword though
you can however implement all the java interfaces you want.
The easiest option I see is to add an IBaseKataSolution interface and
then have the MyKata.rb implement the interface. Then in your calling
code instead of casting it to a BaseKataSolution you would always cast
it to an IBaseKataSolution. If there is underlying functionality in
BaseKataSolution that it needs it could then ALSO subclass
BaseKataSolution and it should get the underlying BaseKataSolution
functionality (you just can't cast it to a BaseKataSolution). The
MyKata.rb would look like this:
require 'java'
java_package 'org.codingkata.unit'
java_import 'org.codingkata.unit.api.IBaseKataSolution'
java_import 'org.codingkata.unit.api.BaseKataSolution'
class MyKata < BaseKataSolution
java_implements IBaseKataSolution
java_signature 'String reply()'
def reply
"hello world"
end
end
If there's no underlying functionality in BaseKataSolution then just
switch it from an abstract class to an interface and that would solve
the problem as well.
Here's a zip file of the hello world kata that compiles and runs but
fails when the calling code tries to cast it to a BaseKataSolution:
http://gabrito.com/files/hello-world-solv-jruby.zip
-Todd