Jasper reports and iReport

Thanks Denis. That helped. There was a mistake with my xml file. I got
it running successfully.

But I got the same problem again. I found out one of the reasons also.
When I created the report design in the iReport UI, the height and width
were some factors for the column headers.

When I run the report in iReport, the PDF was generated successfully.
But when i tried that jasper with my rails application, the file damaged
message was shown. When I adjusted the height and width of the fields in
the report design, I got it working.

Hi

I’ve got the same problem.

— with pdf:
both web-browser crash.
with firebug i get this :

</html

But i don’t know what to think about this

— with rtf.

It works with IE & Firefox. But in both case The report is empty.

Any Idea of the problems??

I try to debug, but no success

Here is my param of my IO.popen call:

java -Djava.awt.headless=true -cp “F:/jasper_test/app/jasper/bin;
F:/jasper_test/app/jasper/lib/commons-beanutils-1.7.jar;
F:/jasper_test/app/jasper/lib/commons-collections-2.1.jar;
F:/jasper_test/app/jasper/lib/commons-logging-1.0.2.jar;
F:/jasper_test/app/jasper/lib/itext-1.3.1.jar;
F:/jasper_test/app/jasper/lib/jasperreports-2.0.5.jar;
F:/jasper_test/app/jasper/lib/jcommon-1.0.0.jar;
F:/jasper_test/app/jasper/lib/jdt-compiler-3.1.1.jar;
F:/jasper_test/app/jasper/lib/jdt-compiler.jar;
F:/jasper_test/app/jasper/lib/jfreechart-1.0.0.jar;
F:/jasper_test/app/jasper/lib/log4j-1.2.13.jar;
F:/jasper_test/app/jasper/lib/poi-3.0.1-FINAL-20070705.jar;
F:/jasper_test/app/jasper/lib/xalan.jar”
XmlJasperInterface -ortf -fF:/jasper_test/app/reports/custrep.jasper -
x/customer_list_result/invoice_customers/customer

Here is my xml_data param of the pipe.write method

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

<customer_list_result>
<invoice_customers>

smalltown
1
A Nuino


big town
2
3D-Design


Expensivetown
3
International Inc.

</invoice_customers>
</customer_list_result>

Does anybody see something wrong.

If i run this line
“XmlJasperInterface -ortf -fF:/jasper_test/app/reports/custrep.jasper -
x/customer_list_result/invoice_customers/customer”
in my command line interface (win xp), I’ve got this error:
[fatal Error] :3:1 Content is not allowed in prolog.

Does it mean something to someone??

I’ve got this error:
[fatal Error] :3:1 Content is not allowed in prolog.

It could be a malformed XML stream…

See http://www.judahfrangipane.com/blog/?p=53

Could this be the reason?

quotes from above link - The link does not work for me at present for
some reason.

QUOTE:
In an XML document the first thing before anything else you declare the
type like so:

Correct:

PLAIN TEXTXML:

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

Incorrect:

PLAIN TEXTXML:
helloworld<?xml version="1.0" encoding="utf-8"?>

Note: The text formatter that I use adds a space between the less than
sign and first question mark. That should not be there. In your document
do not include the space.

Anything before the first character generates this error. If you do not
see any characters you may have an invisible character. Then you would
have to erase (backspace) up to that first character and retype the xml
declaration or take a similar approach.
END QUOTE:

QUOTE:
Suggestions:

  • Copy the text in your file and paste it into Notepad. Notepad strips
    or converts non standard codes. It is not fool proof but seems to work
    in most cases.

  • Create a new file using your standard process. Copy the contents of
    your original file and paste them into the new file. The content being
    everything minus the beginning and end tags.
    END QUOTE:

Denis :slight_smile:

I try this but it doesn’t work.

Could u send me your example app that work. It could help me.

Hi Jef,

If your report is blank you most likely did not tick the box in the
connection properties that says :
use the report XPATH expression when filling the report

Regards

Denis

Also make sure to select XPATH2 as the query type
and define the query as per attached
ie.
the XML tags:-
<customer_list_result>
<invoice_customers>

become:

/customer_list_result/invoice_customers/customer

in the XPATH2 query window.

Denis

Could u send me your example app that work. It could help me.

your email address ?

Denis

Hi,

I have got some problem. I have integrated the JasperReport with my ROR
application.

When I use “pipe.read” it reads the stream but not fully. As there is a
special character which ruby takes as a EOF character. It’s hex value is
“0x1a”. When this character is reached, ruby stops reading the stream.

Please give a suggestion to solve this issue.

Thanks in advance…

Sorry

[email protected]

thanks

2008/4/30 Denis M. [email protected]:

Thanks a lot Denis. That clearly solved my problem.

Hi,

I noticed a change in the document.rb file on
IntegratingRubyAndJasperReports.
(It is difficult to determine the changes that are made due to the
method of updating the wiki :slight_smile:

The mode needs to be set as ‘w+b’ for Windows.
This seems to have improved the stability of my PDF reports.
I thought you might be interested. It COULD be the cause of your error ?

Code fragment follows -note MODE is SET TO “w+b” for Binary mode in
WINDOWS. and passed as ‘mode’ to the Java call.

Regards
Denis

when /mswin32/
mode = “w+b” #windows requires binary mode
#Dir.foreach(“app/jasper/lib”) do |file|
Dir.foreach(Dir.getwd+"/app/jasper/lib") do |file|
interface_classpath << “;#{Dir.getwd}/app/jasper/lib/”+file if
(file != ‘.’ and file != ‘…’ and file.match(/.jar/))
end
else
mode = “w+”
Dir.foreach(Dir.getwd+"/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

  # removed--------------
  #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|
# removed ------------------

   # edited -------------------------------
   IO.popen "java -Djava.awt.headless=true -cp 

“#{interface_classpath}” XmlJasperInterface -o#{output_type}
-f#{Dir.getwd}/app/reports/#{report_design} -x#{select_criteria}", mode
do |pipe|
# edited -------------------------------

Karthi kn wrote:

Thanks a lot Denis. That clearly solved my problem.

You’re welcome. It feels good to be right now and again :slight_smile:

Regards

Denis

Hi everyone

I’ve followed your instructions here and at
Peak Obsession, but
no success, or just partial success, my pdf comes 0 bytes

I’m now trying the command line proposed there to get the report, and I
receive the folloing

Exception in thread “main” java.lang.NoClassDefFoundError:
XmlJasperInterface
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: XmlJasperInterface not
found in gnu.gcj.runtime.SystemClassLoader{urls=[],
parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)

I guess it’s something related to XmlJasperinterface (class not found)

there is another place than /app/jasper/lib where I should to
copy this file?, or maybe define $CLASSPATH environment variable?, or
something I’m missing?

BTW: I’m developing in a FedoraC6, with Apache, also using goldberg
(integrated site design for ruby on rails, due to this, I did some
changes to path’s at /app/models/document.rb, but test if its geting the
right files and it is)

in advance, thanks for your time

I guess it’s something related to XmlJasperinterface (class not found)

there is another place than /app/jasper/lib where I should to
copy this file?, or maybe define $CLASSPATH environment variable?, or
something I’m missing?

The file should be in /BIN not /LIB

ie. where your appplication is XXXXXX

C:\InstantRails\rails_apps\XXXXXX\app\jasper\bin

Regards

Denis

but my result pdf file is still getting 0 bytes

any comment is welcome, regards Mauricio

Ae you actually getting a PDF file displayed that you can save, with no
data (a blank page?) Or are you getting a corruption when the PDF is
being written ?

The XML selection query used in the Rails code in the line-

send_doc(
render_to_string(:template => ‘accounting/customer_list’, :layout =>
false),
‘/customer_list_result/invoice_customers/customer’,
‘custrep’,
‘CustomerReport’,
’pdf’)

viz. /customer_list_result/invoice_customers/customer

must match the XML quey used when designing the Report to ensure you do
actually select the record/nodes you want to target.

Sorry, I’m not familiar with your development variation :frowning:

Denis

Denis M. wrote:

I guess it’s something related to XmlJasperinterface (class not found)

there is another place than /app/jasper/lib where I should to
copy this file?, or maybe define $CLASSPATH environment variable?, or
something I’m missing?

The file should be in /BIN not /LIB

ie. where your appplication is XXXXXX

C:\InstantRails\rails_apps\XXXXXX\app\jasper\bin

Regards

Denis

Thank you a lot Denis for taking time to answer this

I’ve just did a mistake writing prior post, my XmlJasperinterface.class
file actually is at /app/jasper/bin, and I did also:

export CLASSPATH=/app/jasper/bin

but my result pdf file is still getting 0 bytes

Sorry if did not try achieving this with a pure rubyOnRails application
(without using Goldberg) before post here, I’ll try that this afternoon
because I’m suspecting Goldberg may be asking the report for
authentication when it try to get data from
/app/views/XXXXX/customer_list

nevertheless, it’s almost sure I have a problem with ruby accesing
XmlJasperinterface, as the message I recevie from command line attempt
states

any comment is welcome, regards Mauricio

Denis M. wrote:

Ae you actually getting a PDF file displayed that you can save, with no
data (a blank page?) Or are you getting a corruption when the PDF is
being written ?
.
.
.
Sorry, I’m not familiar with your development variation :frowning:

Denis

thank you Denis

I’m receiving a “file” with 0 bytes (absolutely blank page, no source
code), I can’t save it

it seems that I first must be sure that java command line works

Karthi kn wrote:

It may be because of the invalid character in the stream. Try to read
the stream in binary mode. I mean, Use “w+b” instead of “w+”, when you
open the pipe using IO.popen().

thank you Karthi, but I’m not using ruby to call XmlJasperInterface,
just the java command line

I was able to define CLASSPATH, so the java call it’s working now, but
with same results that before… XmlJasperInterface.class is giving me a
corrupted pdf file, when I try to open it, acrobat says “there was an
error opening this document. A file read error has ocurred”

I reviwed the Xpath and it’s the same that I set in the report, also
update all jar files to IReport3.0

thanks anyway

It may be because of the invalid character in the stream. Try to read
the stream in binary mode. I mean, Use “w+b” instead of “w+”, when you
open the pipe using IO.popen().