I have written this code to show a simple report using iReport 4.7.1.
private void printReport() {
try {
JRTableModelDataSource dataSource = new JRTableModelDataSource(
new JTable().getModel());
String reportSource = "C:\\Reports\\report1.jrxml";
Map<String, Object> params = new HashMap<String, Object>();
params.put("Name", "SriLanka");
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
JasperViewer.viewReport(jasperPrint, false);
} catch (Exception e) {
e.printStackTrace();
}
}
Here are my libraries:
- commons-beanutils-1.8.0.jar
- commons-collections-2.1.1.jar
- commons-digester-2.1.jar
- commons-logging-1.1.1.jar
- jasperrreports-4.7.1.jar
- jasperreports-applet-4.7.1.jar
- jasperreports-javaflow-4.7.1.jar
- groovy-all-1.7.5.jar
and NetBeans output shows this warning
Oct 08, 2012 2:57:31 PM net.sf.jasperreports.engine.component.ComponentsEnvironment findBundles WARNING: Found two components for namespace http://jasperreports.sourceforge.net/jasperreports/components
and here is the .jrxml file:
<?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="report1" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5174594e-de3c-4b09-932b-c6665bf6a34b">
<parameter name="Name" class="java.lang.String" isForPrompting="false"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement uuid="fd02a8bc-548b-41c1-aed5-2a7c2e257704" x="210" y="23" width="157" height="36"/>
<textElement>
<font size="18"/>
</textElement>
<textFieldExpression><![CDATA[$P{Name}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The report opens but doesn't show any text.