Jasper reports and huge XML as data source

I have a huge one .xml

as a data source (about 100MB). How to prepare pdf file with this xml efficiently and without java.lang.OutOfMemoryError: Java heap space


HashMap<String, Object> params = new HashMap<String,Object>();
// below i get: java.lang.OutOfMemoryError
Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(dataSource)); 
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
jasperPrint = JasperFillManager.fillReport(jasperReport, params);



source to share

2 answers

You can increase the heap if possible. But creating a DOM for a 100MB XML file plus creating a pdf document in one JVM really does take a lot of memory. Try to parse the input file with an event-based SAX parser. This should significantly reduce memory footprint.



Besides using the best XML parser, also check out Jasper Reports - Virtualizer .



All Articles