1

I'm getting a NoClassDefFoundError error when trying to compile or run a Jasper report.

2012-06-13 14:46:26,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jahtest].[jahtest]] Servlet.service() for servlet jahtest threw exception
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:207)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:172)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)

I have a set of java classes wrapped up in a war file and deployed in JBoss default/deploy folder. I have the jasperreports-4.1.2.jar file in the JBoss default/lib folder so I can't see how there can be a classpath problem because all other jars in the lib folder can be seen.

My front-end app calls a HTTPServlet class which then uses reflection to call the class containing the Jasper code. Everything works fine up until the point where this line is called -

JasperDesign jasperDesign = JRXmlLoader.load(strCompiledReportFile);

The strCompiledReportFile is correct and exists. This all works when I run it through Eclipse, just not when called from my HTTPServlet class.

I'm at the point where I want to ditch Jasper because I've had so many issues with it so this is the last chance saloon.

Cheers for any help you might be able to offer.

Tim
  • 14,999
  • 1
  • 45
  • 68
user1167796
  • 31
  • 2
  • 3
  • Other than having all the required jars in my JBoss default/lib folder, is there anywhere else that they should be referenced? I've tried adding them to the WEB-INF\lib folder of my war file, I've also tried adding them to the C:\Program Files\Java\jdk1.6.0_13\jre\lib folder but still get the same error. – user1167796 Jun 13 '12 at 14:51
  • This is so frustrating! I only get the errors when I try and access the Jasper classes through a servlet. I can access my own class successfully, bu if I call a method that uses any Jasper code then I get this classNotFound error. – user1167796 Jun 14 '12 at 13:59
  • Right, this must be a classpath problem with my servlet. I've determined that the runtime classpath is different when run through Eclipse than when run through my servlet. I've added all the required jars to the web-inf/lib folder in my war file. It still doesn't work! Do I have to set the classpath in a manifest file in my war file? If so how do I do that? – user1167796 Jun 15 '12 at 14:05

3 Answers3

1

I think you are missing few jars that jasper depends on at runtime. Check this thread and make sure you have those jars in your classpath as well.

Community
  • 1
  • 1
helios
  • 2,603
  • 4
  • 21
  • 26
  • Thanks for the suggestion. Just checked and all the suggested jar files are already included in my JBoss default/lib folder. – user1167796 Jun 13 '12 at 14:35
  • I am sure that you are missing some jar at runtime, it's tough to tell which one. Does stacktrace have any more information ? – helios Jun 13 '12 at 14:48
  • Can you check the jars that were present at compile time against the ones at runtime? There should be some jar(s) from compile time that's missing during runtime. – helios Jun 13 '12 at 15:11
  • Just as a reference [here](http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/requirements.html) is the list of required jars to JasperReports. – Jacob Schoen Jun 13 '12 at 17:52
  • How can I check the jars that are used at runtime as opposed to compile time? – user1167796 Jun 14 '12 at 13:56
  • Depends - If there are lot of jar files at compile time, then the fastest way is to use a file/folder comparison tool like Araxis or Beyond Compare. – helios Jun 14 '12 at 14:19
  • Tried various things now. Maybe it was because I was reading a file from the filesystem and Java doesn't like that (or is that just for applets?) so created the file as a long text string and read in using a ByteArrayInputStream - No change. Removed the ajax call to my httpservlet and just called the Jasper class from a simple test servlet - No change. Removed all reflection and called methods directly - No change. But the damn thing still works in Eclipse! Just what has Eclipse got that I can't see? Eclipse doesn't even have the Jasper jar file in the build path. Been at this for days now! – user1167796 Jun 14 '12 at 14:46
0

I'm not sure if it would also apply to your case, but I had a similar problem recently, where after failing to load a font ("problem reading font data"), Jasper Reports would start giving spurious java.lang.NoClassDefFoundError for many of its classes; this problem was caused because java.awt.Font.createFont(int fontFormat, InputStream fontStream) tried and failed to create a temporary file. The error happened inside Tomcat, but not inside Eclipse; what was happening was that Tomcat automatically configures its JVM to point to its temp folder instead of the default one, and Tomcat's temp folder had been deleted.

Haroldo_OK
  • 6,612
  • 3
  • 43
  • 80
0

If you are trying to integrate jasper with springboot application check whether the .jrxml is in the resources folder.