I am using JasperReports in order to create a reports on an Java web application using tomcat, but I am facing this error which I was not able to quite find a solution on Google. The only topics that I found talked about to add Xerces to the dependencys which I have done but still not changed a thing.
String reportOutput = reportOutputLocation+reportName;
InputStream reportTemplate = getClass().getClassLoader().getResourceAsStream(reportSrcLocation);
JasperDesign jasperDesign = JRXmlLoader.load(reportTemplate);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map<String, Object> paramObjects = new HashMap<String, Object>();
paramObjects.putAll(parameters);
JasperPrint jprint = JasperFillManager.fillReport(jasperReport, paramObjects, conn);
The error happens over here: JRXmlLoader.load(reportTemplate);
This is the stack trace output:
net.sf.jasperreports.engine.JRRuntimeException: Error creating SAX parser
net.sf.jasperreports.engine.xml.BaseSaxParserFactory.createParser(BaseSaxParserFactory.java:99)
net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1456)
net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createDigester(JRXmlDigesterFactory.java:1432)
net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:262)
net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:247)
java.lang.Thread.run(Unknown Source)
<jasper.version>5.6.1</jasper.version>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
As I knew the code was working fine and the issue was in the project setup. The pom.xml was fine and also the dependencys.
What I did in order to get this working was double click on tomcat server on Eclipse.
- Download xercesImpl-2.8.1.jar or any other version
- Click on "Open Launch Configuration"
- Go to the tab "Classpath"
- Click on Bootstrap Entries
- Add External JARs
- Select xercesImpl-2.8.1.jar or any version that you prefer.
Restart server and it should work.