i have jar named test.jar contains following java classes:
test.java
package test; import java.lang.reflect.method; public class test { public static void yoyo(object o) { method[] methods = o.getclass().getmethods(); (method method : methods) { canrun annos = method.getannotation(canrun.class); if (annos != null) { try { method.invoke(o); } catch (exception e) { e.printstacktrace(); } } } } } and interface canrun.java
package test; import java.lang.annotation.elementtype; import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy; import java.lang.annotation.target; @target(value = elementtype.method) @retention(value = retentionpolicy.runtime) public @interface canrun { } and ruby file main.rb
require 'java' require 'test.jar' java_import java::test.test class main def run test.yoyo(main.new) end java_annotation('canrun') def onhi() puts "inside on hi" end end app = main.new app.run and running following command: jruby main.rb
but there no output.
basically,what trying is, calling yoyo() of test.java main.rb , passing object of main in yoyo().then yoyo() in test.java analyze functions of main.rb having annotation canrun , if found call them, in our case onhi should called. checked object passing in yoyo() not null. problem facing onhi not getting called.
i tried lot of things nothing helped.
am using annotation in rb file or please suggest other way.
you annotation not in default package (nor imported) instead :
java_annotation 'test.canrun'
or
java_import "test.canrun" java_annotation :canrun
Comments
Post a Comment