Generating jasper report when the app was compiled in fat jar

0

I've successfully added jasper reports to my java app, and added fonts via font extensions. When i run my app in intelij idea, everything works fine, the report generate with selected font. But, when I compile everything into one unified (single, fat and etc.) jar file, deploy it to the Wildfly and try to generate the report, i get the following error:

2020-04-30 13:44:20,834 ERROR [net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper] (DefaultDispatcher-worker-1) Error loading font family: net.sf.jasperreports.engine.fonts.InvalidFontException: Error loading font "net/sf/jasperreports/fonts/icons/icons.ttf".
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.loadFont(SimpleFontFace.java:206)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:167)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFace(SimpleFontExtensionHelper.java:390)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:311)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontExtensions(SimpleFontExtensionHelper.java:259)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:230)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:187)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:93)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
    at deployment.develop.war//net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:134)
    at deployment.develop.war//net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:86)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:116)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:79)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:251)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:156)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:758)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:739)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1061)
    at deployment.develop.war//ru.myproject.testspring.services.reports.ReportProvider.generateReportInternal(ReportProvider.kt:27)
    at deployment.develop.war//ru.myproject.testspring.services.reports.ReportProvider.generateReportInternal(ReportProvider.kt:10)
    at deployment.develop.war//ru.myproject.testspring.services.reports.AbstractReportProvider$generateReport$1$1.invokeSuspend(AbstractReportProvider.kt:52)
    at deployment.develop.war//kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at deployment.develop.war//kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: java.io.IOException: Problem reading font data.
    at java.desktop/java.awt.Font.createFont0(Font.java:1177)
    at java.desktop/java.awt.Font.createFont(Font.java:1046)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.loadFont(SimpleFontFace.java:198)
    ... 28 more
 
2020-04-30 13:44:20,826 ERROR [net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper] (DefaultDispatcher-worker-1) Error loading font family: net.sf.jasperreports.engine.fonts.InvalidFontException: Error loading font "fonts/TimesFont/times.ttf".
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.loadFont(SimpleFontFace.java:206)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.setTtf(SimpleFontFace.java:167)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFace(SimpleFontExtensionHelper.java:379)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontFamily(SimpleFontExtensionHelper.java:311)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.parseFontExtensions(SimpleFontExtensionHelper.java:259)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:230)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:187)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:93)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
    at deployment.develop.war//net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:134)
    at deployment.develop.war//net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:86)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:116)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:79)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:251)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:156)
    at deployment.develop.war//net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:758)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:739)
    at deployment.develop.war//net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1061)
    at deployment.develop.war//ru.myproject.testspring.services.reports.ReportProvider.generateReportInternal(ReportProvider.kt:27)
    at deployment.develop.war//ru.myproject.testspring.services.reports.ReportProvider.generateReportInternal(ReportProvider.kt:10)
    at deployment.develop.war//ru.myproject.testspring.services.reports.AbstractReportProvider$generateReport$1$1.invokeSuspend(AbstractReportProvider.kt:52)
    at deployment.develop.war//kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at deployment.develop.war//kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at deployment.develop.war//kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: java.io.IOException: Problem reading font data.
    at java.desktop/java.awt.Font.createFont0(Font.java:1177)
    at java.desktop/java.awt.Font.createFont(Font.java:1046)
    at deployment.develop.war//net.sf.jasperreports.engine.fonts.SimpleFontFace.loadFont(SimpleFontFace.java:198)
    ... 28 more

There is my code of font-extension

jasperreports_extension.properties

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.ireportfamily1586778266566=fonts/fontsfamily1586778266566.xml


fontsfamily1586778266566.xml:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
    <fontFamily name="TimesFont">
        <normal><![CDATA[fonts/TimesFont/times.ttf]]></normal>
        <bold><![CDATA[fonts/TimesFont/timesbd.ttf]]></bold>
        <italic><![CDATA[fonts/TimesFont/timesi.ttf]]></italic>
        <boldItalic><![CDATA[fonts/TimesFont/timesbi.ttf]]></boldItalic>
        <pdfEncoding><![CDATA[Cp1251]]></pdfEncoding>
        <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        <exportFonts/>
    </fontFamily>
    <fontSet name="ReportFontSet">
        <family familyName="TimesFont" primary="true"/>
    </fontSet>
</fontFamilies>

I see my font-extension jar in lib folder of my .war file (WEB-INF\lib).

My environment:

jasperreports:6.12.2
Wildfly 19


P.S. And very strange, that i receive the follow error from the logs:

Error loading font family: net.sf.jasperreports.engine.fonts.InvalidFontException: Error loading font "net/sf/jasperreports/fonts/icons/icons.ttf"

because icon.ttf locates in jasper default fonts folder in jasperreports:6.12.2.jar

Joe Musashi's picture
Joined: Apr 7 2020 - 1:20am
Last seen: 11 months 3 days ago

3 Answers:

0

I found the solution of this problem. I use docker container with WildFly and in docker i have Linux, that wasn't configured for fonts. I used following commands:

For enter:

docker exec -it -u 0 wildfly /bin/bash

where wildfly is a container name

For fonts (IT IS SOLUTION)

sudo apt-get install fontconfig
Joe Musashi's picture
Joined: Apr 7 2020 - 1:20am
Last seen: 11 months 3 days ago
0

Your fontsfamily1586778266566.xml is wrong. Edit follow the following code:

<?xml version="1.0" encoding="UTF-8"?>
 
<fontFamilies>
 
    <fontFamily name="Lobster Two">
        <normal>lobstertwo/LobsterTwo-Regular.otf</normal>
        <bold>lobstertwo/LobsterTwo-Bold.otf</bold>
        <italic>lobstertwo/LobsterTwo-Italic.otf</italic>
        <boldItalic>lobstertwo/LobsterTwo-BoldItalic.otf</boldItalic>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded>true</pdfEmbedded>
    </fontFamily>
 
</fontFamilies>

I am Leo's picture
185
Joined: Jan 3 2020 - 3:13am
Last seen: 4 days 58 min ago
0

File was generated by Jasper Studio automatic. And it works in Linux or Windows when i run it without fat jar.

Joe Musashi's picture
Joined: Apr 7 2020 - 1:20am
Last seen: 11 months 3 days ago
Feedback