I need to generate reports in my project which is being developed using Spring 3
. For that I created the report structure using iReport 5.6
(the latest one) and then by using that jrxml
file, I generate the pdf file of that report.
this is my code for that.
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("projectName", projectName);
parameters.put("lotNo", lotNo);
parameters.put("agreementNo", agreementNo);
parameters.put("installmentAmount", installmentAmount);
parameters.put("payableDate", payableDate);
parameters.put("lastDate", lastDate);
parameters.put("address", address);
try {
// compiles jrxml
JasperCompileManager.compileReportToFile("installmentReminder.jrxml");
// fills compiled report with parameters and a connection
JasperPrint print = JasperFillManager.fillReport(reportName + ".jasper", parameters, new JREmptyDataSource());
// export report to pdf
JasperExportManager.exportReportToPdfFile(print, reportName+".pdf");
//open pdf
if (Desktop.isDesktopSupported()) {
try {
File myFile = new File(reportName+".pdf");
Desktop.getDesktop().open(myFile);
} catch (IOException ex) {
// no application registered for PDFs
System.out.println("EXCEPTION: while opening pdf = "+ex);
}
}
} catch (Exception e) {
//throw new RuntimeException("It's not possible to generate the pdf report.", e);
}
I tried generating the required pdf file outside the Spring
environment and it worked fine and generated the file. But in Spring
environment, it gives me this exception
net.sf.jasperreports.engine.JRException: org.xml.sax.SAXParseException: Document root element "jasperReport", must match DOCTYPE root "null"
I searched through the web and found there can be a xml
issue. this is a similar kind of issue and they say that the issue is with xml
and the versions of jasper
and Spring
. But I cannot understand what is wrong in my case.
definition of jrxml file :
<jasperReport xmlns="http://ift.tt/1bXYvZE" xmlns:xsi="http://ift.tt/ra1lAU" xsi:schemaLocation="http://ift.tt/1bXYvZE http://ift.tt/18OQfHh" name="installmentReminder" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="7076bf4f-0d49-4132-9890-1b6559c3ed21">
spring libraries :
Please help me to solve this issue please. Thanks in advance !
Edit :-
why I am saying this issue is related with Spring
is this;
- I ran the same code in
Eclipse IDE
in aJavaSE
project and it worked perfet. - When I try to run the same code in
Spring Tool Suit IDE
, it gave me the above exception. (I use the same libraries in both cases)
Any one please help me to understand whether there is a conflict between Spring
version and Jasper
version.
Aucun commentaire:
Enregistrer un commentaire