# Talking to Java Code from Ruby

**URL:** <https://www.ruby-forum.com/t/talking-to-java-code-from-ruby/51079>\
**Category:** Ruby\
**Created:** [December 25, 2005, 8:43pm UTC](https://www.ruby-forum.com/t/talking-to-java-code-from-ruby/51079 "2005-12-25T20:43:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kevben](https://www.ruby-forum.com/u/kevben)\
**Post date:** [December 25, 2005, 8:43pm UTC](https://www.ruby-forum.com/t/talking-to-java-code-from-ruby/51079/1 "2005-12-25T20:43:29Z")

</div>

I’m attempting to use YAJB to talk to JasperReports from Ruby.

Please scream at me right now if there’s a better way to get to  
JasperReports.

This is what I have so far:

-------------------BEGIN------------------  
require ‘yajb/jbridge’  
require ‘fileutils’  
include JavaBridge

$REPORTS\_LIB\_DIR = “/home/kevin/dli/” + “backend/reports\_module/lib/”

path = “$CLASSPATH”  
FileUtils::cd($REPORTS\_LIB\_DIR) do  
Dir[“\*.jar”].each { |name|  
path += “:#{$REPORTS\_LIB\_DIR + name}/”  
}  
end

JBRIDGE\_OPTIONS = {  
:classpath =\> path  
}

jimport “net.sf.jasperreports.engine.\*”  
jimport “java.util.HashMap”

jasperReport = jnew :JasperCompileManager  
jasperReport.compileReport(  
“/home/kevin/dli/backend/reports\_module/report\_templates/VirtualizerReport.jrxml”);

hash = jnew :HashMap  
data = jnew :JREmptyDataSource

jasperPrint = jnew :JasperFillManager  
jasperPrint.fillReport(jasperReport, hash, data)  
-------------------END------------------

This does just fine for compiling the report, but when I try to call  
fillReport, the world blows up:  
/usr/local/lib/site\_ruby/1.8/yajb/bstream.rb:655:in `value': java.lang.RuntimeException (JavaBridge::JException) No such method: fillReport in net.sf.jasperreports.engine.JasperFillManager java.lang.RuntimeException: No such method: fillReport in net.sf.jasperreports.engine.JasperFillManager at jbridge.BridgeServer.generalCall(BridgeServer.java:145) at jbridge.BridgeServer.call(BridgeServer.java:179) at jbridge.comm.binstream.BStream_JBServer$2.send(BStream_JBServer.java:140) at jbridge.comm.binstream.MessageServer$MethodInvocation.run(MessageServer.java:456) at jbridge.InvocationPool$Worker.workloop(InvocationPool.java:97) at jbridge.InvocationPool$Worker.access$000(InvocationPool.java:55) at jbridge.InvocationPool$1.run(InvocationPool.java:62) at java.lang.Thread.run(Unknown Source) from /usr/local/lib/site_ruby/1.8/yajb/bstream.rb:810:in `send\_message’  
from /usr/local/lib/site\_ruby/1.8/yajb/bstream.rb:1048:in  
`send_message' from /usr/local/lib/site_ruby/1.8/yajb/comm_bstream.rb:59:in `send\_message\_to\_java’  
from /usr/local/lib/site\_ruby/1.8/yajb/jbridge.rb:506:in  
`__send_message_to_java' from /usr/local/lib/site_ruby/1.8/yajb/jbridge.rb:739:in ` **call** ’  
from /usr/local/lib/site\_ruby/1.8/yajb/jbridge.rb:685:in  
`method\_missing’  
from ./testing\_stub.rb:35

I could see why it would get confused. It’s an overloaded method. I’ve  
poured over the docs for yajb but haven’t found anywhere that explains  
how to  
force calls of overloaded methods. I would like to use yajb because  
it’s  
pure ruby and pure java, meaning no compiling, and installs are easy.  
The  
communication being slow makes almost zero difference to me because I  
won’t  
be doing very much communication, just spawning off processor hogs with  
the  
thing.

So is there a way to specify types for overloaded methods, or do I need  
to use  
RJB ([http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge](http://arton.no-ip.info/collabo/backyard/?RubyJavaBridge))? Or do I  
need  
to be slapped across the face with a wet trout for not seeing the easy  
solution?

---

<div class="post-metadata">

**Author:** ![kevben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kevben](https://www.ruby-forum.com/u/kevben)\
**Post date:** [December 26, 2005, 6:43pm UTC](https://www.ruby-forum.com/t/talking-to-java-code-from-ruby/51079/2 "2005-12-26T18:43:37Z")

</div>

On Sunday 25 December 2005 13:42, Kevin B. wrote:

> I’m attempting to use YAJB to talk to JasperReports from Ruby.
> 
> Please scream at me right now if there’s a better way to get to  
> JasperReports.

For anyone who cares, I’m using RJB and it’s working fine now. So that  
was my  
solution. 🙂

---

<div class="post-metadata">

**Author:** ![kevben](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/90ced4/32.png) [@kevben](https://www.ruby-forum.com/u/kevben)\
**Post date:** [January 4, 2006, 3:58am UTC](https://www.ruby-forum.com/t/talking-to-java-code-from-ruby/51079/3 "2006-01-04T03:58:15Z")

</div>

Hi,

Sorry for late response.

I think JasperFillManager does not have the method  
fillReport(JasperCompileManager,Map,JRDataSource).

How about following code?  
-------------------BEGIN------------------  
(snip)  
:  
manager = jnew :JasperCompileManager  
jasperReport = manager.compileReport(path\_to\_template)  
:  
-------------------END------------------

> I could see why it would get confused. It’s an overloaded method. I’ve  
> poured over the docs for yajb but haven’t found anywhere that explains how to  
> force calls of overloaded methods.

The yajb tries to search the overloaded method as java does.  
So, giving appropriate arguments, you can choose the method.

Because the difference of typing between ruby (duck-typing) and java  
(strong typing) is great, I’m not sure that the method searching code  
is complete. If you are interesting in the code, please see the url  
(served by gonzui at RAA)

[http://raa.ruby-lang.org/gonzui/markup/yajb/src/java\_src/jbridge/MethodFinder.java](http://raa.ruby-lang.org/gonzui/markup/yajb/src/java_src/jbridge/MethodFinder.java)
