java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.1.1
Issue
- Our DR server throws
NoClassDefFoundError
but our Prod server, which has identical configuration with DR one, doesn't.
23:00:02,080 ERROR [org.quartz.core.JobRunShell] (schedulerFactory_Worker-3) Job XXXX threw an unhandled Exception: : java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:55) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446) [jasperreports-javaflow-4.7.0.jar:4.7.0]
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:849) [jasperreports-javaflow-4.7.0.jar:4.7.0]
...
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113) [spring-context-support-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at org.quartz.core.JobRunShell.run(JobRunShell.java:206) [quartz-2.0.0.jar:]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:548) [quartz-2.0.0.jar:]
Resolution
- Make sure that those servers have exactly the same configuration. We found that the problematic class,
net.sf.jasperreports.engine.util.JRStyledTextParser
, has a static initializer trying to load fonts. And if a related GUI library is not installed on the OS, it will fail to be initialized. Please confirm that your DR environment has a proper GUI library installed, which is likely found in the Prod environment. Or confirm that there is a system property,"-Djava.awt.headless=true"
, in your startup script.
Diagnostic Steps
From jasperreports-4.7.0-project.zip
:
public class JRStyledTextParser implements ErrorHandler
{
private static final Log log = LogFactory.getLog(JRStyledTextParser.class);
private static final Set<String> AVAILABLE_FONT_FACE_NAMES = new HashSet<String>();
static
{
//FIXMEFONT do some cache
List<FontFamily> families = ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class);
for (Iterator<FontFamily> itf = families.iterator(); itf.hasNext();)
{
FontFamily family =itf.next();
AVAILABLE_FONT_FACE_NAMES.add(family.getName());
}
AVAILABLE_FONT_FACE_NAMES.addAll(
Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())
);
}
...
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments