Settings.xml:
mirror1 central mirror1 https://repo.maven.apache.org/maven2/
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
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/Blank_A4_Paramv2.jrxml"; String fileNamePdf = "E:/Jasper/Blank_A4_Paramv2.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); String first_language = "Java"; String second_language = "Structured text"; HashMaphm = new HashMap (); hm.put("Param_First_Language", first_language); hm.put("Param_Second_Language", second_language); 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