Pergunta

I have a java 7 application in which it is necessary to create a PDF from xml-files. Using iReport designer I successfully created the report. This report contains nested subreports. I have a parameter 'SUBREPORT_DIR' in the masterreport which is passed on to the subreports. All the .jasper files (master and subreports) are included in the project resources in a '/jasper/'-directory.

In java I do the following:

Map<String, Object> params = new HashMap<>();
params.put("SUBREPORT_DIR", "\\jasper\\" );
String sJasper = "/InvoiceMasterReport.jasper";
try (InputStream jasper = InvoiceTransformer.class.getResourceAsStream(sJasper)) {
     iReportTransformer irt = new iReportTransformer(file, pdfResult, jasper, params);
     irt.transformToPDF();
}

and in the transformToPDF() method:

JRXmlDataSource jrSource = new JRXmlDataSource(noNS.toFile(), "/INVOICE");
JasperPrint jp = JasperFillManager.fillReport(_jasperStream, _params, jrSource);        
jrSource.close();               

JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, _pdfResult.toString());
exporter.setParameter(JRPdfExporterParameter.PDFA_CONFORMANCE, JRPdfExporterParameter.PDFA_CONFORMANCE_1A);

URL url = this.getClass().getResource("/jasper/sRGB_v4_ICC_preference.icc");        
String iccPath = Paths.get(url.toURI()).toAbsolutePath().toString();
exporter.setParameter(JRPdfExporterParameter.PDFA_ICC_PROFILE_PATH, iccPath);
exporter.exportReport();

Now for the problem: This all works in development on a Windows machine, but when I deploy on linux I receive a JRException on the exportReport()-method:

Exception be.vanmarcke.edixml.CM8.TransformationException: net.sf.jasperreports.engine.JRException: Resource not found at : /jasper/SubReportHeader.jasper on /opt/EDIXML_docs/2014/April/29/16/invoices/T_1398780297363.xmlMessage: net.sf.jasperreports.engine.JRException: Resource not found at : /jasper/SubReportHeader.jasperStackTrace: 
be.vanmarcke.edixml.CM8.TransformationException: net.sf.jasperreports.engine.JRException: Resource not found at : /jasper/SubReportHeader.jasper 
at be.vanmarcke.edixml.CM8.InvoiceTransformer.XMLInvoiceToPDF_iReport(InvoiceTransformer.java:66)
at be.vanmarcke.edixml.invoices.InvoiceFileHandler.createPDF(InvoiceFileHandler.java:333)
at be.vanmarcke.edixml.invoices.InvoiceFileHandler.commitValidDocument(InvoiceFileHandler.java:358)
at be.vanmarcke.edixml.invoices.InvoiceFileHandler.commitDocument(InvoiceFileHandler.java:180)
at be.vanmarcke.edixml.general.AbstractFileHandler.handleParsedInputFiles(AbstractFileHandler.java:290)

....

I have tried several values for the SUBREPORT_DIR param, none that work though. Does anyone have any suggestions or alternate solutions for this?

Foi útil?

Solução

Well, I 'fixed' this by not including the .jasper files as resources in the jar file. Instead I load the files from an external folder.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top