Jasper reports and iReport

On Feb 8, 1:50 pm, FlexRails [email protected] wrote:

Hey Jon,

I’m glad you got it to work. I’m looking forward to your plugin,
although the hard part will probably always be the iReport and Java
part. I’ve never developed a plugin before so I don’t know if I can be
of assistance. Are you going to put the Java stuff also inside the
plugin directory ?

That’s my plan. I’ve created a few plugins (some only shared between
internal projects here at work and a couple released to the wild), so
I’m not worried about that part. It also looks like I should be able
to integrate jasperreports into the plugin and stay true to jasper’s
GPL licensing.

The one thing I’m still wondering about is that
XmlJasperInterface.class file and where it comes from, how it’s
licensed, etc. It seems like it would be necessary to include it with
the plugin, but do I need to include the source? Does it have it’s
own copywrite and license that needs to be included? Anybody know who
originally wrote that code?

Do you think I could improve the description of the whole process ?

Not sure. One problem I ran into is my project uses RESTful routes,
so I needed to do a little extra to generate the original xml file and
the report, but I think including those instructions might have made
it more confusing for people not using RESTful routes, and those of us
who are should already know what we need to do. Other than that, it
appears my whole problem was really my typo.

I suppose I left the log4j-1.2.13.jar because the one from the iReport
lib was a lower version. I’m going to test however if it is also
working with the version that is included in iReport and will let you
know here.

I’m currently using the two log4j’s that come in iReport and it seems
to work, but I’m not doing anything complicated, so my not even be
exercising that code to find out it’s not good enough.

Hey Jon,

I’m glad you got it to work. I’m looking forward to your plugin,
although the hard part will probably always be the iReport and Java
part. I’ve never developed a plugin before so I don’t know if I can be
of assistance. Are you going to put the Java stuff also inside the
plugin directory ?

Do you think I could improve the description of the whole process ?

I suppose I left the log4j-1.2.13.jar because the one from the iReport
lib was a lower version. I’m going to test however if it is also
working with the version that is included in iReport and will let you
know here.

On Feb 8, 4:11 pm, FlexRails [email protected] wrote:

The download contains also the XmlInterface.java source file. In that
file there is the e-mail address of the guy who wrote it. You could
maybe mail him about it.

Hehe, I actually just found his address through a different route.
But based on what you found, it looks like I’ve definitely got the
right guy. So, we’ll see what he says.

Hi,
I used the HowTo to install JasperReports in my Rails-application.
It works for rtf-files, but it doesn’t work for pdf. No message in the
logfiles :frowning: Anyone any idea?
Sometimes even rtf doesn’t work and I get a ‘Exception in thread
“main” java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/
JRDataSource’. Anyone any idea for that?
Thanks!
Eike

The download contains also the XmlInterface.java source file. In that
file there is the e-mail address of the guy who wrote it. You could
maybe mail him about it.

Thanks to Herman Jansen for his work on this :slight_smile:

On the
http://wiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports

page in the example xml code it has an inconsistency ?

‘LIST’ (opening reference,versus, ‘LOOKUP’ closing reference)
Would that cause a problem ?

I’m struggling to follow this tutorial. :frowning:

<?xml version="1.0" encoding="UTF-8"?>

<customer_list_result>

</customer_lookup_result>

Denis

I’ve finally achieved some measure of success…
When I try to display data as PDF in IE , it now launched Adobe Reader,
but gives me an error message

‘The file is damaged and could not be repaired’.

I suspect a typo in Document.rb , and I’ve looked at it 'till I’m blue
in the face and cannot see it…
Are all the path references correct ? I had to insert a reference to
‘app/’ into the original tutorial code before the path in
Dir.foreach("/jasper/lib"

else I got a message :

Errno::ENOENT in CustomersController#report
No such file or directory - jasper/lib

Anybody spot a typo below ?
(Win XP = ROR ver 1.7.)

Denis


class Document < ActiveRecord::Base
include Config
def self.generate_report(xml_data, report_design, output_type,
select_criteria)
report_design << ‘.jasper’ if !report_design.match(/.jasper$/)
interface_classpath=Dir.getwd+"/jasper/bin"
case CONFIG[‘host’]
when /mswin32/
Dir.foreach("/app/jasper/lib") do |file|
interface_classpath << “;#{Dir.getwd}/jasper/lib/”+file if
(file != ‘.’ and file != ‘…’ and file.match(/.jar/))
flash[:notice] = interface_classpath
end
else
Dir.foreach("/app/jasper/lib") do |file|
interface_classpath << “:#{Dir.getwd}/app/jasper/lib/”+file if
(file != ‘.’ and file != ‘…’ and file.match(/.jar/))
end
end
result=nil
IO.popen “java -Djava.awt.headless=true -cp
“#{interface_classpath}” XmlJasperInterface -o#{output_type}
-f#{Dir.getwd}/app/reports/#{report_design} -x#{select_criteria}”, “w+”
do |pipe|
pipe.write xml_data
pipe.close_write
result = pipe.read
pipe.close
end
return result
end
end

Check again if you have all the necessary classes from the iReports
lib directory.

I’ve finally achieved some measure of success…
When I try to display data as PDF in IE , it now launched Adobe Reader,
but gives me an error message

‘The file is damaged and could not be repaired’.

Additionally, I now see that in the server console it generate output
as follows:
%PDF-1.4
%ooxe
3 0 obj <<Length 277/Filter/Flate… an so on.
-about 4 lines of garbage…

It looks like it might be an Adobe PDF header …
hmmm… must be the xmljasperinterface acting up…
java environment ??

jeez 1 it’s so frustrating …iReports looks so good :slight_smile:

Denis

Herman Jansen wrote:

Check again if you have all the necessary classes from the iReports
lib directory.

Thank for your suggestion. I’ve actually re-installed everything from
ground zero, because I had tried everything to resolve this issue.
In the process I’ve upgraded to RoR ver 2.0 (I has been at 1.7). That
involved jumping through a few hoops. I re installed iReports 2.0.4 and
JasperReports 2.0.5(very recent release)

I had double checked the lib replication dimension, and they were
identical, save for a version indicator in one file :- Log4J
files…(two). I’ve used the latest version 1.2.13.

Just for the record…

Directory of C:\InstantRails\rails_apps…jasper\lib

13/12/2006 10:20 188,671 commons-beanutils-1.7.jar
08/12/2003 20:50 165,119 commons-collections-2.1.jar
15/01/2008 20:32 26,388 commons-logging-1.0.2.jar
01/07/2005 13:21 1,553,403 itext-1.3.1.jar
15/01/2008 20:32 1,922,698 jasperreports-2.0.4.jar
20/12/2005 17:45 294,514 jcommon-1.0.0.jar
15/01/2008 20:32 1,212,369 jdt-compiler-3.1.1.jar
20/12/2005 17:45 1,072,312 jfreechart-1.0.0.jar
04/12/2005 18:00 358,180 log4j-1.2.13.jar
22/08/2007 15:48 909,270 poi-3.0.1-FINAL-20070705.jar
15/07/2004 22:46 1,781,922 xalan.jar

Directory of C:\jasper\iReport-2.0.4\lib

15/01/2008 20:32 188,671 commons-beanutils-1.7.jar
15/01/2008 20:32 165,119 commons-collections-2.1.jar
15/01/2008 20:32 26,388 commons-logging-1.0.2.jar
15/01/2008 20:32 18,404 commons-logging-api-1.0.2.jar
15/01/2008 20:32 1,553,403 itext-1.3.1.jar
15/01/2008 20:32 1,922,698 jasperreports-2.0.4.jar
15/01/2008 20:32 1,212,369 jdt-compiler-3.1.1.jar
15/01/2008 20:32 1,072,312 jfreechart-1.0.0.jar
15/01/2008 20:32 352,668 log4j-1.2.8.jar
15/01/2008 20:32 352,291 log4j-1.2.9.jar
15/01/2008 20:32 909,270 poi-3.0.1-FINAL-20070705.jar
15/01/2008 20:32 1,781,922 xalan.jar

Having re-checked everything and still having an Adobe launch with a
corrupt file error, I tried it on another PC. It also has ROR version
2.0 , did NOT have ireports or Jasper installed, save for the files
copied to the …app/jasper/lib.

Amazing ! It worked :slight_smile: . Let joy be unconfined.

Now to figure out why that has happened ?
My PC is :- IntelDualCore , 4 Gig Ram, Win XP SR2 , Java version SE
1.6.0_05-b13. InternetExplorer ver 7.0.5730.11
(This PC is dual boot with Vista 64).

The other PC is;- IntelDualCore , 2 Gig Ram, Win XP SR1 , Java version
1.5.03. InternetExplorer ver 6.

The value set returned by Request.env are more detailed on the former…
I tested this by pasting some code into a view in mycookbook.com - as
the simplest available environment.

See http://wiki.rubyonrails.org/rails/pages/VariablesInRequestEnv

I’m still puzzled as to why it should work on one PC and not another.
Since the application was simply copied from one PC to the other as a
folder within the rails_apps directory - with additionally copying the
MySQL data folder.

If i do not resolve this, I could not deploy to any particular PC
without the overhead of checking this aspect for all possible reports to
generated… ?

Any thoughts on why the variance ? Seems like an environment issue ?

Sorry for goingon so long .
Thanks for your interests and contributions here :slight_smile:

Regards,

Happy St. Patrick’s day( tomorrow) from ireland :slight_smile:

Denis

Just for the record ; revisited

20/12/2005 17:45 294,514 jcommon-1.0.0.jar IS in ROR lib
04/12/2005 18:00 358,180 log4j-1.2.13.jar IS in ROR lib
15/01/2008 20:32 352,668 log4j-1.2.8.jar IS in ROR lib
15/01/2008 20:32 352,291 log4j-1.2.9.jar IS in ROR lib
15/01/2008 20:32 18,404 commons-logging-api-1.0.2.jar not in ROR lib

I have got Jasper Reports to work with Rails. I have blogged it -
Ruby Rails Ruminations: Bringing Jasper Reports, Rails and Rjb together.

I would be interested to read comments.

I am going to try JRuby on Rails and use the inate JVM to do the same
thing.

I did look at the ref in the last reply -very impressive - and i may go
that way.

Meahwhile the saga continues…

I’ve finaly got JasperXMLInterface and Ruby to work - consistently every
time, producing PDF docs. (I did have to amend some of the suggested
code to fix a path error - omission of APP at one point)

Now for the wrinkle…
It was intermittemtly breaking, and it took me a while pin it down.

Reproduce the problem by;
run pdf report - works successfully, save it.
close pdf
close browser
close ruby console
close rails applicatiom dialog box
I → configure database vis MyPHPAdmin
select Customer table
Insert a record , save , browse
close MyPHP
I → Rails applications → Manage Rails applications
Select app,
Start it with Mongrel*(ruby console opens)
select http://localhost:3000/customer_report (should produce a pdf
listing customers)
Adobe Reader displays an error message: There was an error opening the
document. The file is damaged and could not be repaired.

Fix the problem by:
close Adobe Reader
Close browser
close ruby console (=stops server)
close Rails applications dialog box
I → config database MyPHPAdmin
select database
select table Customer
browse
delete last record
close browser
I → Rails applications → Manage Rails applications
Select app,
Start it with Mongrel*(ruby console opens)
select http://localhost:3000/customer_report (should produce a pdf
listing customers)
Adobe Reader opens with the pdf listing - perfect !

Question: Is this normal behaviour ? Would you expect it to be damaged
by the action of opening the database with PHPAdmin ? And what is
damaged exactly ?
It has to be some environment (Win XP?) issue ?

I would welcome comments.

Maybe one should not access the database with PHP ?
(I reminded of the old joke - ‘only whan i laugh’ - Was that a Len
Deighton book ?)

Regards

Denis

“Data—> Report query” in iReport was disabled even after i selected my
data source.

Could it be that you have not yet opened (to create) a new file.
Those buttonsare enabledafter File->New document ?

It does seem a little strange that you can create a data source first
without starting a new document… :slight_smile:

Denis

Hi,

I have also started working on integrating the jasper report and ruby on
rails. I started with creating the report manually in iReport.

I created my XML file data source. Then I tried to create the report.

“Data—> Report query” in iReport was disabled even after i selected my
data source. I don’t know why it happens like this. I am not able to
proceed further.
Any guess???

Please help me to find out the issue.

Thanks in advance…

Thanks for you valuable suggestion. Today is the first day I started
working on iReport. I was doing the same mistake as you said.

Now I am able to run the report from the XML. But I am getting a blank
PDF. No data inside it.

Any guess why???

I have done all the coding for ROR and iReports integration as mentioned
in http://wiki.rubyonrails.org/rails/pages/howtointegratejasperreports

When I run the URL in the browser I am getting a small alert message
saying
“The file is damaged and could not be repaired”

Any guess why it is coming???

Sorry :frowning:
forgot to trim trailing message text :frowning:

Denis

Hi Karthi,

I had that problem several times and it’s difficult to trace.
It means that Adobe Reader is launching put the file created and
delivered to it is malformed, probably due to the XML data stream not
conforming to the data stream presented to iReports when you designed
the report.

Most usually, in my case, it was a malformed XML file, being used as
input.
A:
If the XML input file used to design the report is in any way
different from the XML output by the CUSTOMER_LIST method,(I’m assuming
you used the example -your method may be different), it will fail.
B:
The XPATH2 (note the 2) must be selected for the XPATH query to work
correctly.
(Did your fields display properly when you were designing the report ?)

C:
If the library files (JARS) are not exactly as they were when the
iReport is designed, it will fail -(jar version references excluded).
The JARS which you have in the RoR application folder must be the ones
copied in from the iReport/JasperReport Lib folder. See my list above.

Also a help to:

Look at the ruby console window as you run the report. Does the output
to it give any indication? In this context, I heavily loaded the
document.rb with debug output (puts…) to help me trace the problem.
viz

class Document < ActiveRecord::Base
include Config
def self.generate_report(xml_data, report_design, output_type,
select_criteria)
puts(“Got XML passed as :” + xml_data)
puts(“Got output type as:” + output_type)
puts(“Got reportpassed as:” + report_design )
puts(“Selection criteria is:” + select_criteria)

What does Dir.for each do ??? -this test line reads and lists on

console screen every matching file inc . and … (.=curDir , … =parent
Dir)
#Dir.foreach(“c:/InstantRails/rails_apps/hats/app/jasper/bin”) {|x|
puts("Got " + x) }

NOTE: hats was my appdir name- replace it with yours , if you decide to
insert debug code

Good Luck :slight_smile:
Denis

Karthi kn wrote:

I have done all the coding for ROR and iReports integration as mentioned
in http://wiki.rubyonrails.org/rails/pages/howtointegratejasperreports

When I run the URL in the browser I am getting a small alert message
saying
“The file is damaged and could not be repaired”

Any guess why it is coming???

I’m glad for you :slight_smile:

It’s intersting that the object width/height could be a cause of error.
I did note that it warns you when the objects overlap the boundries by
altering the colour of the object outline.

I wonder would you look at my post of 26.03.2008 16:16 and comment ?
Are you in Linux or Windows ? and do you use PHPadmin.
It still seems strange to me that the PDF file creation can be broken by
using PHP admin.

Regards

Denis