eddy
eddy

Reputation: 4413

Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

I'm trying to display my reports on the browser , but I keep getting this error:

enter image description here

the strange thing about this, is that it only happens when I attempt to generate the reports from the version installed on the server, but not when I do it locally from my pc

Have you any idea why this is happening ?

Upvotes: 29

Views: 106168

Answers (23)

Master.Aurora
Master.Aurora

Reputation: 1038

This seems like a Headless mode issue. You need to set the java.awt.headless property to true. That can be done using:

static {
    System.setProperty("java.awt.headless", "true");
}

Or, by setting the headless property in your tomcat startup command as -Djava.awt.headless=true

Upvotes: 11

Claudio Ciccarone
Claudio Ciccarone

Reputation: 75

For us the problem was that we had to use the standard Openjdk version not the alpine one. I assure you that all the other fixes don't work.

Upvotes: 0

slartidan
slartidan

Reputation: 21576

Upgrade your jasperreports-dependency.

I got a similar stacktrace, when using this outdated version of jasperreports:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.1.0</version>
</dependency>

This fixed my issues:

<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>6.17.0</version>
</dependency>

Upvotes: 1

FiruzzZ
FiruzzZ

Reputation: 826

Using Payara (4 in my case) already has -Djava.awt.headless=true, We are using Jasper 6.6.0 but downgraded to 6.4.0 (for another dependency) we had the same problem when did a fresh install of payara4 with oracle JDK 8u281, downgrading to 8u181 or 8u171 solved it

Upvotes: 0

Hondaman900
Hondaman900

Reputation: 139

For me this error was because I had upgraded JasperSoft Studio and thereafter new or edited reports were compiled in a newer JasperReports version and were therefore unreadable by the server. There is a compile compatibility mode in Studio, but I couldn't get it to work, and the version I was running on the server (6.6.0) wasn't listed as an option in the list of compatibility versions (and using other "close" versions didn't work either).

I ended up installing a legacy Studio version 6.6.0, and recompiled my reports in it. When I deployed the new .jasper files to the server they worked right away and all is well again.

Upvotes: 0

vsingh
vsingh

Reputation: 6759

There are 2 steps to solve this problem.

  1. -Djaav.awt.headless=true in startup script or vm options

  2. Install the fonts

    yum install fontconfig

Then you can verify

rpm -qa | grep font
fontpackages-filesystem-1.44-8.el7.noarch
dejavu-fonts-common-2.33-6.el7.noarch
fontconfig-2.13.0-4.3.el7.x86_64
dejavu-sans-fonts-2.33-6.el7.noarch

This is on CentOS 7. We had been using Google Noto fonts and thought that we do not need any font installation but was wrong.

Upvotes: 0

codemania23
codemania23

Reputation: 1071

I know I'm late but couldn't resist answering this one to help out a lot of guys in trouble. After a lot of trial and error, figured out that xml-apis jar is excluded in catalina.properties of tomcat. Remove it from there and it should work. Didn't notice any side effects till now, works great.

Also, make sure the fonts are installed and check gradle/pom for merge strategy if any exclusions are made on xml-apis jar.

BTW, this problem started coming for us after upgrading to jdk11 and moving from tomcat 8 to 9.

Upvotes: 3

Mr.Turtle
Mr.Turtle

Reputation: 3090

For me the issue was regarding a bug in AdoptOpenJDK: https://github.com/AdoptOpenJDK/openjdk-build/issues/682

I fixed the issue by installing ttf-dejavu manually in my dockerfile

FROM adoptopenjdk/openjdk8:alpine-jre

# Workaround for wrong font configuration in adoptopenjdk
# https://github.com/AdoptOpenJDK/openjdk-build/issues/682
RUN apk update && apk upgrade \
   && apk add --no-cache ttf-dejavu \
   # Install windows fonts as well. Not required..
   && apk add --no-cache msttcorefonts-installer \
   && update-ms-fonts && fc-cache -f

AND by running the application with the flag -Djava.awt.headless=true

Upvotes: 10

Isuru Nuwanthilaka
Isuru Nuwanthilaka

Reputation: 173

In my case problem was with the jdk8 which I was using to build docker image, but after some search I switched to jre. That fixed my bug. I think you can try any image rather than using jdk8.

Upvotes: 0

Isuru Nuwanthilaka
Isuru Nuwanthilaka

Reputation: 173

I got this error while deploying springboot app (including jasper reporting) in docker container.The problem was with openjdk:8-jdk-alpine which I used for building docker container environment. That has a bug in fonts support. Therefore I switched to openjdk:8-jre (or OpenJDK 7 versions will also help) and it worked for me. I spent days to fix this bug.

Upvotes: 7

RRN
RRN

Reputation: 21

You can try make a downgrade to jdk7, it's works to me.

sorry my english!

Upvotes: 0

Chinthaka Dinadasa
Chinthaka Dinadasa

Reputation: 3461

I've faced the same issue on my development machine. Basically it was happened due to problem in application server (Apache tomcat)

Basically I've accidentally deleted the "temp" folder in server root. So jasper cant compile the report and proceed with the report generation.

Upvotes: 0

Valentin Gr&#233;goire
Valentin Gr&#233;goire

Reputation: 1150

A little late, but here is why we had this problem... We recently started developing with IntelliJ instead of Eclipse. We simply forgot to run IntelliJ as administrator... We had done this with Eclipse for a long time already, but simply didn't think about it with IntelliJ. In the end, I guess the fonts weren't found or a folder was not found since there were insufficient rights to read/write on the c drive.

Upvotes: 1

Josef Bodnar
Josef Bodnar

Reputation: 21

In our case it helped to delete the temp server (thus making sure there are no jar duplicities) and restart server. Hint: try this in case if the error starts occurring after a new release (but worked before and nothing relevant changed in the release)

Upvotes: 0

plrenaudin
plrenaudin

Reputation: 23

This might help ,I had the same error and every other solution didn't work.

I fixed it by updating to java8.

Upvotes: 0

W. Goeman
W. Goeman

Reputation: 1714

I searched several hours for the same issue, and my solution is none of the others mentioned.

Due to a bad update of my jasper reports version I had multiple versions of the jasperreports jar file on my classpath. Make sure you only have a single jasperreports jar file...

Upvotes: 1

user2870979
user2870979

Reputation: 181

In my case i was using Arial fonts for this i have configured arial fonts in irfonts.xml which was like below

<fontFamily name="Arial">
<normal><![CDATA[fonts/arial.ttf]]> </normal>
<bold><![CDATA[fonts/arialbd.ttf]]>
</bold>
<italic><![CDATA[fonts/ariali.ttf]]>
</italic>
<boldItalic><![CDATA[fonts/arialbi.ttf]]>
</boldItalic>
<pdfEmbedded><![CDATA[true]]>
</pdfEmbedded></fontFamily>
but it should be like :
<fontFamily name="Arial">
<normal><![CDATA[fonts/arial.ttf]]><
/normal>
<bold><![CDATA[fonts/arialbd.ttf]]></bold>
<italic><![CDATA[fonts/ariali.ttf]]></italic>
<boldItalic><!
[CDATA[fonts/arialbi.ttf]]></boldItalic>
<pdfEmbedded><!
[CDATA[true]]></pdfEmbedded>
</fontFamily>
so their was a space before the end tag of each tag in above configuration file.
i fixed it by removing space between them.

Upvotes: 0

Denys
Denys

Reputation: 146

Got the same error - apparently JRStyledTextParser is using dependency from xml-apis By adding xml-apis I got it fixed

<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>

Upvotes: 0

Stepan
Stepan

Reputation: 1226

This can as well be caused by missing/inaccessible Java 'temp' directory. In Font.java, temp files are being created:

Files.createTempFile("+~JF", ".tmp").toFile();

On one system, the 'temp' dir was missing under Tomcat folder but Java was configured to use it:

-Djava.io.tmpdir=C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\temp

BTW. first time around, after restarting Tomcat, the service was actually throwing an IOException, but then JasperReports cached something and on subsequent calls the stack trace was exactly as reported here.

Upvotes: 7

zwets
zwets

Reputation: 286

For those still running into this issue: on Ubuntu Server 12.04 with headless OpenJDK JRE, it was simply solved by

apt-get install ttf-dejavu-extra

Upvotes: 10

fernando
fernando

Reputation: 51

this may be problems with memory, reboot the server.

Upvotes: 4

Isnah
Isnah

Reputation: 41

To resolve the issue, do the following:

  1. Switched from Open JDK to Sun JDK
  2. Installed MS Core Fonts
  3. Packaged JasperReport font library jar with the application

Upvotes: 4

Mark Ellul
Mark Ellul

Reputation: 1906

This is a missing jars in the class path issue.

I had this issue and found that with by adding the missing jars to the class path it resolved the issue.

From the below article java.dzone.com article I found that the minimal jars necessary are...Now The versions numbers have changed but with these libraries only I managed to get it working.

  • jasperreports-2.0.4.jar
  • commons-digester-1.7.jar
  • commons-collections-2.1.jar (commons-collections.jar)
  • commons-logging-1.0.2.jar
  • commons-beanutils.jar
  • iText-2.0.7.jar (used infor PDF exporting)

Upvotes: 7

Related Questions