I recently Started on Extending JAVA in jruby
can some one share a light on this
I have a java program call Adding.java
Which look like this
class Adding
{
// private = local to this class
public static int addIntegers(int a, int b)
{
return (a+b);
}
public static void main(String[] args)
{
// system.in reader (e.g. the input from the console)
Adding a = new Adding();
System.out.print(a.addIntegers(10,20));
}
}
I successfully manage to import the java class in jruby
like this
require “rubygems”
require “java”
module Java
java_import ‘Adding’
end
class A < Java::Adding
end
now when I create a new Object for class A
as we normally do it ruby
like
A.new
I seem to get the Following error
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.jruby.javasupport.proxy.JavaProxyClassFactory.invokeDefineClass(JavaProxyClassFactory.java:256)
at
org.jruby.javasupport.proxy.JavaProxyClassFactory.generate(JavaProxyClassFactory.java:221)
at
org.jruby.javasupport.proxy.JavaProxyClassFactory.newProxyClass(JavaProxyClassFactory.java:174)
at
org.jruby.javasupport.proxy.JavaProxyClass.getProxyClass(JavaProxyClass.java:122)
at
org.jruby.javasupport.proxy.JavaProxyClass.get_with_class(JavaProxyClass.java:693)
at org.jruby.javasupport.Java$4.call(Java.java:705)
at
org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:626)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:122)
at
org.jruby.java.proxies.ConcreteJavaProxy$2.call(ConcreteJavaProxy.java:39)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:122)
at org.jruby.RubyClass$SpecificArityNew.call(RubyClass.java:793)
at
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:178)
at
org.jruby.java.proxies.ConcreteJavaProxy$3.call(ConcreteJavaProxy.java:132)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:289)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:108)
at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:61)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.RootNode.interpret(RootNode.java:129)
at
org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:98)
at org.jruby.RubyKernel.eval(RubyKernel.java:1045)
at
org.jruby.RubyKernel$s_method_0_3$RUBYFRAMEDINVOKER$eval.call(org/jruby/RubyKernel$s_method_0_3$RUBYFRAMEDINVOKER$eval.gen:65535)
at
org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:160)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:66)
at
org.jruby.ast.FCallManyArgsNode.interpret(FCallManyArgsNode.java:60)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:113)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:127)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:147)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:66)
at org.jruby.ast.CallManyArgsNode.interpret(CallManyArgsNode.java:59)
at org.jruby.ast.FCallOneArgNode.interpret(FCallOneArgNode.java:36)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:221)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:188)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:186)
at org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:199)
at
org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:118)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:294)
at
org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:228)
at org.jruby.runtime.Block.yieldSpecific(Block.java:99)
at org.jruby.ast.ZYieldNode.interpret(ZYieldNode.java:25)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:201)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:180)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:155)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:172)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373)
at
org.jruby.runtime.InterpretedBlock.yieldSpecific(InterpretedBlock.java:259)
at org.jruby.runtime.Block.yieldSpecific(Block.java:117)
at org.jruby.ast.YieldTwoNode.interpret(YieldTwoNode.java:31)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.IfNode.interpret(IfNode.java:117)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at org.jruby.ast.RescueNode.executeBody(RescueNode.java:199)
at
org.jruby.ast.RescueNode.interpretWithJavaExceptions(RescueNode.java:118)
at org.jruby.ast.RescueNode.interpret(RescueNode.java:110)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:346)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:303)
at org.jruby.runtime.Block.yield(Block.java:194)
at org.jruby.RubyKernel.loop_1_9(RubyKernel.java:1251)
at
org.jruby.RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER$loop_1_9.call(org/jruby/RubyKernel$s_method_0_0$RUBYFRAMEDINVOKER$loop_1_9.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:132)
at
org.jruby.ast.FCallNoArgBlockNode.interpret(FCallNoArgBlockNode.java:32)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:346)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:303)
at org.jruby.runtime.Block.yield(Block.java:194)
at org.jruby.RubyContinuation.enter(RubyContinuation.java:106)
at org.jruby.RubyKernel.rbCatch(RubyKernel.java:1093)
at
org.jruby.RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.call(org/jruby/RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:319)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:157)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:172)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:160)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:164)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:299)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:117)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:122)
at
org.jruby.ast.CallNoArgBlockNode.interpret(CallNoArgBlockNode.java:64)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:139)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:156)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:289)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:108)
at org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:61)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at
org.jruby.runtime.InterpretedBlock.evalBlockBody(InterpretedBlock.java:373)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:346)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:303)
at org.jruby.runtime.Block.yield(Block.java:194)
at org.jruby.RubyContinuation.enter(RubyContinuation.java:106)
at org.jruby.RubyKernel.rbCatch(RubyKernel.java:1093)
at
org.jruby.RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.call(org/jruby/RubyKernel$s_method_1_0$RUBYFRAMEDINVOKER$rbCatch.gen:65535)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:319)
at
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:157)
at
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:172)
at
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.EnsureNode.interpret(EnsureNode.java:96)
at org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
at org.jruby.ast.NewlineNode.interpret(NewlineNode.java:104)
at org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
at
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:180)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:172)
at
org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:309)
at
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:148)
at usr.local.bin.jirb.file(jirb:13)
at usr.local.bin.jirb.load(jirb)
at org.jruby.Ruby.runScript(Ruby.java:684)
at org.jruby.Ruby.runNormally(Ruby.java:567)
at org.jruby.Ruby.runFromMain(Ruby.java:413)
at org.jruby.Main.run(Main.java:286)
at org.jruby.Main.run(Main.java:128)
at org.jruby.Main.main(Main.java:97)
Caused by: java.lang.IllegalAccessError: class
org.jruby.proxy.Adding$Proxy0 cannot access its superclass Adding
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
… 148 more
ArgumentError: unable to create proxy class for class Adding : null
from (irb):6:in `new_proxy’
from (irb):6
What is this
Thanks