Having some problems to call java methods with java + jruby-jars

Hi,

Please note that I’ve a specific setup (available at
https://github.com/cmichon/jruby) and I already know for sure that
what I’m going to report works in standard jruby.

I’m trying to speed up some mathematical calculations through java
code. Since I felt that java extensions (all the way) seemed hard, I
found a simple example to try out my minimal expectations:

And this is giving me problems… I hope an expert of java+jruby
internals could help me out here :slight_smile:

1/ I compile the following Hi.java file and make it a jar file Hi.jar:
class Hi {
public Hi() {
}
void f() {
System.out.println(“hi”);
}
}

2/ I try the following hi.rb script using jruby-jars approach:
require ‘java’
include_class Java::Hi
Hi.new.f

=> it should say ‘hi’

3/ launching “java -cp
jruby-core-1.6.0.RC2.jar;jruby-stdlib-1.6.0.RC2.jar;Hi.jar
org.jruby.Main hi.rb”, I get the following error
hi.rb:3:in (root)': undefined method f’ for #Java::Hi:0x932fe
(NoMethodError)

This works with standard expanded jruby setup, but not with a
jruby-jars approach…

Am I missing some lines, tweaks or switches to make this works out of
the box ?

Thanks in advance for any pointers.


Christian

The f method only has package visibility - what happens if you make it
public?

On Fri, 2011-02-18 at 15:21 +0100, Christian MICHON wrote:

}
org.jruby.Main hi.rb", I get the following error
hi.rb:3:in (root)': undefined methodf’ for #Java::Hi:0x932fe
(NoMethodError)

This works with standard expanded jruby setup, but not with a
jruby-jars approach…

Am I missing some lines, tweaks or switches to make this works out of the box ?

Thanks in advance for any pointers.


Nick G.
Developer @ Media Service Provider
+44 207 729 4797

On Fri, Feb 18, 2011 at 4:00 PM, Nick G. [email protected]
wrote:

The f method only has package visibility - what happens if you make it
public?

Good point, which I forgot to mention: I already tried that path. I
had an updated version of the code with 2 public methods.

Then I realized I could be missing a public as well in front of the
class itself… and with this extra one it works… :slight_smile:

Thanks!
Christian