Esteve Camps Esteve Camps - 5 months ago 113
Java Question

JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser

When trying to export on WebLogic 11g, it throws NoClassDefFound exception. I checked the application WAR and jasperreports-3.7.4.jar is included in WEB-INF/lib folder. What is the error?

StackTrace


java.lang.NoClassDefFoundError:
net/sf/jasperreports/engine/util/JRStyledTextParser
at
net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:181)
at
net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:76)
at
net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:86)
at
net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:56)
at
net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:142)
at
net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:78)
at
net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at
org.springframework.web.servlet.view.jasperreports.AbstractJasperReportsView.fillReport(AbstractJasperReportsView.java:676)
at

Answer

Finally, I've got it working. I detected the root Exception, which was thrown before NoClassDefFoundError:net/sf/jasperreports/engine/util/JRStyledTextParser :

java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment

The Sun AWT classes on Unix and Linux have a dependence on the X Window System. When you use these classes, they expect to load X client libraries and be able to talk to an X display server. This makes sense if your client has a GUI; unfortunately, it's required even if your client uses AWT but does not have a GUI (which is my case, generating a report from a web application)

The way to bypass this, is setting a system property java.awt.headless=true on system startup.