1

I generate jasper report using the code below which works fine under windows. The fonts in the jasper report are embedded. The fonts are imported to the app using the maven dependency jasperreports-fonts. Specifically DeJaVu Sans.

JasperDesign jasperDesign = JRXmlLoader.load(jasperStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, jrDataSource);
JasperViewer.viewReport(jasperPrint, false);

However, when deploying the app in linux environment it displays the error below;

java.lang.ExceptionInInitializerError

Caused by: net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: Problem reading font data.
    at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:108)
    at net.sf.jasperreports.engine.fonts.SimpleFontFace.<init>(SimpleFontFace.java:128)
    at net.sf.jasperreports.engine.fonts.SimpleFontFace.getInstance(SimpleFontFace.java:67)
    at net.sf.jasperreports.engine.fonts.SimpleFontFamily.setNormal(SimpleFontFamily.java:99)
Caused by: java.io.IOException: Problem reading font data.
    at java.awt.Font.createFont0(Font.java:1000)
    at java.awt.Font.createFont(Font.java:877)
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
n1ckgun
  • 49
  • 1
  • 2
  • 11

1 Answers1

0

Strangle this is probably a java.io.tmpdir problem.

Change the permissions of the temp directory or set it as you wish

System.setProperty("java.io.tmpdir","whereYouLike");

For more info see: Environment variable to control java.io.tmpdir?

Note: if you are using tomcat (it's probably using tomcat's temp dir) and it is better to add:

-Djava.awt.headless=true
Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • Unfortunately none of the suggestions work. If I put headless true then it throws exception for java.awt.HeadlessException, I'm using Jetty server – n1ckgun Mar 31 '16 at 07:31
  • @n1ckgun I still think it's a temporary directory problem, maybe this can help http://www.eclipse.org/jetty/documentation/current/ref-temporary-directories.html – Petter Friberg Mar 31 '16 at 08:46
  • What I did was I tried to start jetty by specifying the temporary directory as below: /usr/bin/java -Djetty.state=/jetty/jetty.state -Djetty.port=8080 -Xmx1024m -Djetty.logs=/jetty/logs/ -Djetty.home=/jetty -Djava.io.tmpdir=/jetty/tempdir -jar /jetty/start.jar etc/jetty-logging.xml etc/jetty-started.xml where /jetty/tempdir has no problems with permissions – n1ckgun Mar 31 '16 at 09:12
  • @n1ckgun Try to check thats the tempory director it is using Sys out getProperty("java.io.tmpdir") – Petter Friberg Mar 31 '16 at 09:34
  • checked. It is the temporary directory. The path is correct – n1ckgun Mar 31 '16 at 11:51
  • Btw, if it helps. The first error I received was: No X11 DISPLAY variable was set, but this program performed an operation which requires it. Then I set the export display. After that I am facing this error. Also is there a way to fix No X11 without export display command? Because sometimes export display becomes empty and I have to set it again.. – n1ckgun Mar 31 '16 at 11:53
  • This will have some different ways http://stackoverflow.com/questions/662421/no-x11-display-variable-what-does-it-mean – Petter Friberg Mar 31 '16 at 12:17
  • Did you found the answer? I am facing same issue with linux – Asif Ansari Aug 10 '21 at 06:26