0

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> 
Guizinhobeback
  • 86
  • 1
  • 14
  • 2
    Possible duplicate of [JasperReports: Getting JRRuntimeException: Error creating SAX parser](http://stackoverflow.com/questions/17715967/jasperreports-getting-jrruntimeexception-error-creating-sax-parser) – Alex K Feb 24 '17 at 16:35
  • What version of JR are you using? Which libs are at cp? – Alex K Feb 24 '17 at 16:41
  • @AlexK I have edited the question and added the version of jasper and also the dependency of xerces that I have added on pom.xml – Guizinhobeback Feb 24 '17 at 17:49
  • @AlexK I have tried the post that you mentioned and added Xerces at the dependency of my project, but that did not work – Guizinhobeback Feb 24 '17 at 18:03
  • Which libs are at cp? – Alex K Feb 24 '17 at 18:09
  • @AlexK If you mean libraries on the build path of the project. JRE System Library and Maven Dependencies. Which in Maven dependency includes xsdlib-2013.6.1.jar and jasperreports-5.6.1.jar – Guizinhobeback Feb 24 '17 at 18:42
  • This is nice post as well [Dealing with “Xerces hell” in Java/Maven?](http://stackoverflow.com/questions/11677572/dealing-with-xerces-hell-in-java-maven) – Petter Friberg Feb 24 '17 at 20:35
  • @PetterFriberg This code is working in another similar project, but is not working on mine, I think this might be a configuration issue or something set on pom.xml. – Guizinhobeback Mar 02 '17 at 19:39
  • I'm sorry but with information in question the best answer I can give you is that this seems like a "Xerces hell" problem, it's a famous problem it depends on different versions of different library's I bet you have this problem, try to clean up libraries used, check what jasper-reports distributes etc. and good luck (at least get some comfort that we all have gone through this) – Petter Friberg Mar 02 '17 at 20:18

1 Answers1

0

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.

Guizinhobeback
  • 86
  • 1
  • 14