Home > jrubyandjavainterface

jrubyandjavainterface

Jrubyandjavainterface is a project mainly written in JAVA and SHELL, it's free.

jruby class implements java interface test

JRuby classes generated by "jrubyc" are different that generated by "jrubyc --javac". If you want to implement Java inteface in JRuby use "jrubyc --javac" command instead of "jrubyc".

[1 case] jrubyc --javac: public class SimpleImplementation extends RubyObject implements SimpleJavaInterface { (...) }

[2 case] jrubyc: public class SimpleImplementation extends AbstractScript { (...) }

[2 case] generete error: "incompatible types" for code:

SimpleJavaInterface sji = new SimpleImplementation();

===================================================== how to run code:

update variables in run.sh
bash run.sh

... output:

===================================================== jruby jar: [/home/rakk/.m2/repository/org/jruby/jruby/1.6.0/jruby-1.6.0.jar]

===================================================== jrubyc --javac

...............compile SimpleImplementation.rb Generating Java class SimpleImplementation to output_jrubyc_with_javac/SimpleImplementation.java javac -d output_jrubyc_with_javac -cp /home/rakk/dev/bin/langs/jruby/lib/jruby.jar:SimpleJavaInterface-1.0.jar:/home/rakk/.m2/repository/org/jruby/jruby/1.6.0/jruby-1.6.0.jar:. output_jrubyc_with_javac/SimpleImplementation.java ...............we get... output_jrubyc_with_javac/SimpleImplementation.java (...)

public class SimpleImplementation extends RubyObject implements SimpleJavaInterface { private static final Ruby ruby = Ruby.getGlobalRuntime(); private static final RubyClass metaclass;

(...) output_jrubyc_with_javac/SimpleImplementation.class (...) public class SimpleImplementation extends RubyObject implements SimpleJavaInterface {

private SimpleImplementation(Ruby ruby, RubyClass rubyclass)

(...)

jrubyc --java

...............compile SimpleImplementation.rb Generating Java class SimpleImplementation to output_jrubyc_with_java/SimpleImplementation.java ...............we get... output_jrubyc_with_java/SimpleImplementation.java: (...)

public class SimpleImplementation extends RubyObject implements SimpleJavaInterface { private static final Ruby ruby = Ruby.getGlobalRuntime(); private static final RubyClass metaclass;

(...)

jrubyc

...............compile SimpleImplementation.rb Compiling SimpleImplementation.rb to class SimpleImplementation ...............we get... output_jrubyc/SimpleImplementation.class: (...) import org.jruby.runtime.*; import org.jruby.runtime.builtin.IRubyObject;

public class SimpleImplementation extends AbstractScript {

private static void setPosition(ThreadContext threadcontext, int i)
{
    threadcontext.setFileAndLine("SimpleImplementation.rb", i);

(...)

Previous:rtklib