Executing a Java jar file from my Rails app

Using the following as a reference:
http://wiki.rubyonrails.org/rails/pages/HowtoGenerateJFreeCharts

I’m trying to build some charts and I need to call a .jar file from
within my controller. Here’s my code:

pipe = IO.popen("java -jar /raid/projects/Dashboard/charting/

requestByProject.jar “+params[:name]+”")
pipe.close

This gives me nothing, however, if I run the command via the command
line then it returns the images I need.

I’m running Rails through JRuby on a Sun Solaris machine if that helps
at all.

Thanks.

I’m running Rails through JRuby on a Sun Solaris machine if that helps
at all.

Yes, it makes a difference. The wiki article assumed you were running
ruby, not JRuby. That’s why the article uses a command-line invocation
of java.

In JRuby, you should be able to do it natively via require ‘java’ and
include_class, instead of invoking java on the command line.

This should get you started:
http://kfahlgren.com/blog/2007/04/12/more-jruby-play-jfreechart/

  • Mark.