Tomcat:JRStyledTextParser未初始化.java.awt设置为true [英] Tomcat: JRStyledTextParser not Initialized. java.awt is set to true

查看:92
本文介绍了Tomcat:JRStyledTextParser未初始化.java.awt设置为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到 java.lang.NoClassDefFoundError:无法初始化类net.sf.jasperreports.engine.util.JRStyledTextParser

完整的堆栈跟踪为:

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.

还有大约10个(这是我的第一个问题,所以我不能全部参加).

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

我尝试过:

  1. 设置 java.awt.headless = true .

我是在代码中完成的:

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

(返回预期的真).

我在JVM选项中做到了:

I did it in JVM Options:

我将CATALINA_OPTS设置为 -Djava.awt.headless = true .符合预期.

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

没有帮助.

我在DejaVu Sans中使用.jrxml对其进行了测试,并将jasperreports-fonts-6.2.2.jar包含在路径中,并在Sans Serif中对其进行了测试.我检查了哪些字体可用于JVM并进行了测试.没有成功.

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.

有人建议检查jasperreports jars的版本-我也检查过.我有6.2.2的所有罐子.版本:

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.

我使用joda-time-2.9.3(不知道它如何连接到问题,但是一个建议是使用joda;无论如何我还是从一开始就使用它),项目SDK是Java 1.8.0_51(有将其更新为8的建议-与我已经在使用的无关,并且我的Tomcat正常(在其中一种情况下,缺少工作文件夹会导致类似的问题).

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).

我想念什么?

调试时,我遇到了JRGraphEnvInitializer类中的initializeGrophEnv()方法,该方法会引发util.graphic.environment.initialization.error:

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()));

有趣的是,SunGraphicsEnvironment中的方法getAvailableFontFamilyNames()返回了一个由274个元素组成的有效数组(来自调试器的打印屏幕,位于链接下方):

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

推荐答案

首先,感谢大家的帮助.您反应如此之快,让我更加深入=)问题已解决.

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

我的错误是在库中同时包含了 jasperreports-6.2.2.jar jasperreports-javaflow-6.2.2.jar .您还记得,堆栈跟踪中的最后一个方法是 JRBaseFiller 的初始化.两个jar的存在引起了冲突,因为它们都包含一个 net.sf.jasperreports.engine.fill 包,其中包含一个 JRBaseFiller 类.

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.

我只留下了 jasperreports-javaflow-6.2.2.jar .它不能单独工作.我又添加了两个库: jfreechart-1.0.19.jar (以前的版本未包含所有必需的类)和 jcommon-1.0.8 . java.lang.NoClassDefFoundError 消失了.

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.

这篇关于Tomcat:JRStyledTextParser未初始化.java.awt设置为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆