Settings.xml:
mirror1 central mirror1 https://repo.maven.apache.org/maven2
Dependencies:
net.sf.jasperreports jasperreports 6.8.0 jar compile commons-collections commons-collections commons-beanutils commons-beanutils commons-digester commons-digester commons-logging commons-logging commons-digester commons-digester 2.1 compile false net.sf.jasperreports jasperreports-fonts 6.8.0
Java code:
package com.mycompany.mavenprojectdemov1; import java.util.HashMap; import net.sf.jasperreports.engine.*; import net.sf.jasperreports.engine.JREmptyDataSource; import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.design.JasperDesign; import net.sf.jasperreports.engine.xml.JRXmlLoader; /** * Hello world! * */ public class App { public static void main( String[] args ) { String fileNameJrxml = "E:/Jasper/HelloPDF.jrxml"; String fileNamePdf = "E:/Jasper/HelloPDFv2.pdf"; try { System.out.println("Loading the .JRMXML file ...."); JasperDesign jasperDesign = JRXmlLoader.load(fileNameJrxml); System.out.println("Compiling the .JRMXML file to .JASPER file...."); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); HashMaphm = new HashMap (); System.out.println("filling parameters to .JASPER file...."); JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperReport, hm, new JREmptyDataSource()); System.out.println("exporting the JASPER file to PDF file...."); JasperExportManager.exportReportToPdfFile(jprint, fileNamePdf); System.out.println("Successfully completed the export"); } catch (Exception e) { System.out.print("Exception:" + e); } } }
No comments:
Post a Comment