2

I keep getting java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

The full stacktrace is:

java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:108)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:69)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:200)
net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:215)
net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:115)
net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:583)
net.sf.jasperreports.engine.JasperRunManager.runToPdf(JasperRunManager.java:455)
net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:870)
com.evnica.interop.main.ReportServlet.createReport(ReportServlet.java:119)
com.evnica.interop.main.ReportServlet.doGet(ReportServlet.java:96)
com.evnica.interop.main.ReportServlet.service(ReportServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

I have searched for the solution and found a bunch.

and about 10 more (this is my first question so I can't enlist them all).

I have tried:

  1. To set java.awt.headless=true.

I did it within code:

 static {
    System.setProperty("java.awt.headless", "true");
    System.out.println(java.awt.GraphicsEnvironment.isHeadless());
 }

(returns true as expected).

I did it in JVM Options: enter image description here

I set CATALINA_OPTS to -Djava.awt.headless=true. Echoes as expected.

It didn't help.

I tested it with.jrxml with DejaVu Sans and included jasperreports-fonts-6.2.2.jar in the path, and I tested it with Sans Serif. I checked which fonts were available to JVM and tested with them. No success.

There were suggestions to check versions of jasperreports jars - I checked it too. I have all the jars of 6.2.2. version:

jasperreports-6.2.2.jar, 
jasperreports-fonts-6.2.2.jar, 
jasperreports-javaflow-6.2.2.jar.

I use joda-time-2.9.3 (have no idea how it's connected to the problem, but one advice was to use joda; I used it from the beginning anyway), project SDK is java 1.8.0_51 (there was an advice to update to 8 - not relevant as I already use it), and my Tomcat is OK (the absent work folder caused similar problem in one of the cases).

What am I missing?

EDIT: While debugging I came to a method initializeGrophEnv() in JRGraphEnvInitializer class, which throws a util.graphic.environment.initialization.error:

AVAILABLE_FONT_FACE_NAMES.addAll(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));

It's interesting that the method getAvailableFontFamilyNames() in SunGraphicsEnvironment returns a valid array of 274 elements (printscreen from debugger under link):

enter image description here

Community
  • 1
  • 1
evnica
  • 300
  • 3
  • 11
  • Did you try to debug the code (JasperReports API)? – Alex K May 25 '16 at 09:13
  • @Alex K, yes I did. It goes to JRGraphEnvInitialazer class, public static synchronized void initializeGraphEnv(), and throws exception from AVAILABLE_FONT_FACE_NAMES.addAll(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames())); – evnica May 25 '16 at 10:10
  • 1
    Can you add the "caused by:" in your stack trace, null pointer when getting Font.version? – Petter Friberg May 25 '16 at 11:40
  • 1
    Could you also put a breakpoint in the static block of JRStyledTextParser? It might be that you have a font extension jar that fails to load. Your talks about two errors, NoClassDefFoundError for JRStyledTextParser at JRBaseFiller.(JRBaseFiller.java:108) and another in JRGraphEnvInitializer.initializeGraphEnv? Which one are you getting? – dada67 May 25 '16 at 14:21
  • @PetterFriberg, sorry for misunderstanding. What I initially provided is the root cause. The exception thrown is javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71) This is followed by the root cause that I provided above. So, the net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:108) is the deepest level in the stack trace that I can see without debugging. – evnica May 26 '16 at 09:16
  • and in stacktrace you read caused by?, there is a deeper issue, which probably is related to this GraphicsEnvironment.getLocalGraph‌​icsEnvironment().getAvailableFontFamilyNames() and I would bet it is related to a font installed on the macchine. – Petter Friberg May 26 '16 at 11:37

1 Answers1

2

First of all, thanks everyone for help. You responded so fast, and made me dig deeper =) The problem is solved.

My error was to have both jasperreports-6.2.2.jar and jasperreports-javaflow-6.2.2.jar in the libraries. As you remember, the last method in the stack trace was the initialization of JRBaseFiller. The presence of two jars caused a conflict, as both contain a package net.sf.jasperreports.engine.fill with a JRBaseFiller class in it.

I left the jasperreports-javaflow-6.2.2.jar only. It didn't work on its own. I added two more libraries: jfreechart-1.0.19.jar (previous versions didn't contain all the needed classes) and jcommon-1.0.8. The java.lang.NoClassDefFoundError is gone.

evnica
  • 300
  • 3
  • 11