aspose file tools*
The moose likes Other Open Source Projects and the fly likes JasperReports: Compatible jar libraries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JasperReports: Compatible jar libraries" Watch "JasperReports: Compatible jar libraries" New topic
Author

JasperReports: Compatible jar libraries

Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Hi,
I am reading and searching this forum for an answer, and found a lot of help but not for this question.
I use iReport.3.5 for my Report designing.
I have following libraries in my classpath.

itext-1.0.1
jasperReport-3.0.0.jar
poi-3.9-20121203.jar
poi-ooxml-3.9-20121203.jar
poi-ooxml-schemas-3.9-20121203.jar

I need to generate PDF and XLS reports.
The problem is: This combination works for PDF but not for xls
(java.lang.NoSuchMethodError: org.apache.poi.hssf.usermodel.HSSFCell.setEncoding(S)V)
I have tried various combinations of (itext from 1.0.1 to 2.1.7), JasperReport from 3.0.0 5.0.1) and poi 3.0 to 3.9 and get either PRINTSCALING problem for PDF ofr setEncoding...
Does anyone has a good combination of these jar files that work for PDF and XLS....
Any help is appreciated...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
The JasperReports download comes with all dependent libraries. Using those together would seem to offer the best chances of success; just blindly trying various versions of various libraries is futile, IMO.


Ping & DNS - my free Android networking tools app
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Dear Ulf,

Thanks for the reply....
I would love it the problem resolution is that simple.
Just because of your advice, I did download JasperReport-5.1.2 and re-ran the process. (JasperReport download has only 1 jar.. Correct me if I am wrong).
PDF always works but for XLS it gives me the same error.
It seems that the JasperReport...jar has dependencies on POI, and ITEXT.. and hence I posted the question.
Please help me with the compatible version of these.....

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

Here's the page which tells you what jars are required: http://community.jaspersoft.com/wiki/jasperreports-library-requirements
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
The file I downloaded from http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%205.1.0/ (jasperreports-5.1.0-project.tar.gz) came with all jars included in the "lib" directory.
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Thanks a lot.. I am 99% there...
One more problem though

For Exporting to TXT and RTF format (Which I also need)..

I get the following error.
Java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Float
net.sf.jasperreports.engine.JRAbstractExporter$ParameterOverrideResolver.getFloatParameter(JRAbstractExporter.java:266)

It seems there is a bug, reported 2010.. Is there a solution to this?

Thanks in Advance....
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Vinay

You state a bug was reported in 2010 for the problem so what does the bug report give as a status?
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
James..

http://community.jaspersoft.com/questions/533397/jrtextexporter-commented-out-jasperserver-37

Mentions this as a bug-report. But I cannot find any updates on the status. (Tried Googling it).
I have also tried JasperReport-5.1.2.jar (To see if this was fixed in the later release but apparently not)...
Any help is appreciated...

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

That bug is for Jasper Report Server, a separate web application to the library (jars) you are using. I don't think that is the source of your problem.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Did you try the bundled version of Jasper Reports as suggested by Ulf? You cannot simply swap the Jasper Reports jar in and out as each version will have its own set of jars as dependencies.
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Thanks James, I really appreciate you looking into it..
But now I have this problem...

1. I create a .jrxml, .jasper from iReport-3.5.0
2. And my challenge is to allow the user to create PDF/XLS/xml/TXT/RTF/CSV of his/her choice.
3. And my problem is TXT and RTF generation blows up on line JRAbstractExporter.java:266 for Class-cast.

Is there a way to resolve this. To me it looks like it's the JasperReports library. So I tried a better version.
If anyone has a solution please post, It will be a lot of help.

Thanks

This was a bundled version from jasperreport-5.1.0 .. (all itext, poi, and jasperreports supplied by that version).
I did not pick other jars (e.g. batik..., log4j..., serlet-apr...jar etc. as I did not need those).
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Can you post your jrxml file for the report causing the problem?
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Sure.. I can do that.. Here it is.....

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="OdLimitReport" pageWidth="1100" pageHeight="595" orientation="Landscape" columnWidth="1060" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="bankName" class="java.lang.String"/>
<parameter name="totAccts" class="java.lang.String"/>
<field name="accountNo" class="java.lang.String"/>
<field name="nameCity" class="java.lang.String"/>
<field name="officer" class="java.lang.String"/>
<field name="dbPrompt" class="java.lang.String"/>
<field name="crPrompt" class="java.lang.String"/>
<field name="odLimitAmt" class="java.lang.String"/>
<field name="odLimitDate" class="java.lang.String"/>
<field name="odComment" class="java.lang.String"/>
<field name="reason1" class="java.lang.String"/>
<field name="reason2" class="java.lang.String"/>
<field name="reason3" class="java.lang.String"/>
<field name="fundLimit" class="java.lang.String"/>
<background>
<band/>
</background>
<pageHeader>
<band height="81">
<textField pattern="dd-MMM-yy">
<reportElement x="971" y="30" width="89" height="20"/>
<textElement textAlignment="Left"/>
<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
<textField>
<reportElement x="971" y="0" width="89" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="910" y="0" width="30" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Page:]]></text>
</staticText>
<staticText>
<reportElement x="911" y="30" width="29" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Date:]]></text>
</staticText>
<line>
<reportElement x="0" y="74" width="1055" height="1"/>
</line>
<staticText>
<reportElement x="361" y="0" width="356" height="30"/>
<textElement textAlignment="Center">
<font size="16" isBold="true"/>
</textElement>
<text><![CDATA[CIF ACCOUNTS WITH OD/FUNDING LIMIT]]></text>
</staticText>
<staticText>
<reportElement x="420" y="30" width="197" height="20"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[FUNDS TRANSFER SYSTEM]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement x="0" y="50" width="302" height="20"/>
<textElement>
<font size="14"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{bankName}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="33">
<staticText>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[ACCOUNT NO.]]></text>
</staticText>
<staticText>
<reportElement x="132" y="0" width="195" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[NAME AND CITY]]></text>
</staticText>
<staticText>
<reportElement x="420" y="0" width="100" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[OD AMOUNT]]></text>
</staticText>
<staticText>
<reportElement x="690" y="0" width="67" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[EXP. DATE]]></text>
</staticText>
<staticText>
<reportElement x="899" y="0" width="127" height="20"/>
<textElement textAlignment="Left">
<font size="12"/>
</textElement>
<text><![CDATA[OFFICER]]></text>
</staticText>
<line>
<reportElement x="0" y="25" width="1055" height="1"/>
</line>
<staticText>
<reportElement x="547" y="0" width="126" height="20"/>
<textElement>
<font size="12"/>
</textElement>
<text><![CDATA[FUNDING AMT.]]></text>
</staticText>
<staticText>
<reportElement x="770" y="0" width="115" height="20"/>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="80">
<textField>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{accountNo}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="132" y="0" width="262" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{nameCity}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="899" y="0" width="156" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{officer}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="132" y="20" width="541" height="20" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{reason1}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="132" y="40" width="541" height="20" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{reason2}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="404" y="0" width="116" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{odLimitAmt}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="690" y="0" width="67" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{odLimitDate}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="770" y="0" width="115" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{odComment}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="132" y="60" width="541" height="20" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{reason3}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="547" y="0" width="126" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{fundLimit}]]></textFieldExpression>
</textField>
</band>
</detail>
<summary>
<band height="23">
<line>
<reportElement x="0" y="21" width="1050" height="1"/>
</line>
<staticText>
<reportElement x="404" y="0" width="67" height="20"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Total Records:]]></text>
</staticText>
<textField isBlankWhenNull="true">
<reportElement x="690" y="3" width="70" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{totAccts}]]></textFieldExpression>
</textField>
<line>
<reportElement x="0" y="1" width="1050" height="1"/>
</line>
</band>
</summary>
</jasperReport>
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Vinay

I will have a look at this tonight when I get home (currently on a train).

Maybe someone else will have solved this for you by then!
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Vinay

When you receive the exception, are you generating the report through iReport or in code?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

As a follow on to my previous post, what values are you passing for each of the fields required for the report (12 in total)?
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
It's called from the code...


jrTextReporter.exportReport();

(jrTextReporter being a JRTextReporter instance).

All Agruments are String. (In fact the totalcount is also a String argument). I do not have any Integer Argument or Float.. It's something internal..

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Can you post the actual code in and around using the exporter?
Vinay Desai
Greenhorn

Joined: Sep 16, 2013
Posts: 8
Here is the code...

protected String jasperPrintToFile (JasperPrint jasperPrint,
String outputType,
String outputFile,
Map<String, Object> paramMap,
List<Map<String, Object>> detailsList,
String sourcePath,
boolean outputToWriter) throws Exception {

try {
JRTextExporter exporter = new JRTextExporter();
StringWriter stringWriter = new StringWriter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
if (outputToWriter)
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, stringWriter);
else
exporter.setParameter(JRExporterParameter.OUTPUT_FILE, new File(outputFile));
exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Integer(10));
exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Integer(10));
exporter.exportReport();
}catch (Exception e){
e.printStackTrace();
}

But James.. Your persistence hit the nail on it's head..
The problem/solution was right in front of me.
The call.....
exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Integer(10));
exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Integer(10));

Use to be Integer ... but now it's Float...
Because I was getting the code for you, I saw it and now it all works.....

exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Float(10));
exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Float(10));

Thanks a lot for thinking with me. Thanks to all... Hope this may help others also.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Vinay

Glad you sorted it.

That was a nasty bug, that parameter is obviously only taken into account when generating RTF or text documents.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JasperReports: Compatible jar libraries