quarkiverse / quarkus-jasperreports

Print reports created using JasperReports using the Java API
https://community.jaspersoft.com/project/jasperreports-library
Apache License 2.0
8 stars 1 forks source link

Error loading font extension in native image #151

Closed redddcyclone closed 3 weeks ago

redddcyclone commented 3 weeks ago

Hello all,

I'm trying to generate a report in my native image application, but I use a custom font extension (I had to generate an Arial font extension because of problems with Arial bold). In dev mode it works fine but on native I get the following error:

10:21:42,492 ERROR [net.sf.jasperreports.engine.fonts.FontExtensionsRegistry] Error loading font extensions from fonts/fontsfamily1723135526544.xml: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Input stream not found at: fonts/fontsfamily1723135526544.xml.
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:189)
        at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.ensureFontExtensions(FontExtensionsRegistry.java:93)
        at net.sf.jasperreports.engine.fonts.FontExtensionsRegistry.getExtensions(FontExtensionsRegistry.java:57)
        at net.sf.jasperreports.extensions.DefaultExtensionsRegistry.getExtensions(DefaultExtensionsRegistry.java:134)
        at net.sf.jasperreports.engine.util.JRStyledTextParser.<clinit>(JRStyledTextParser.java:87)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:115)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:82)
        at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:252)
        at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
        at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:115)
        at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:104)
        at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:529)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:953)
        at com.blahblah.util.RelatorioUtil.geraArquivoRelatorio(RelatorioUtil.java:149)
        at com.blahblah.util.RelatorioUtil.gerarRelatorio(RelatorioUtil.java:74)
        at com.blahblah.util.RelatorioUtil.gerarRelatorio(RelatorioUtil.java:88)
        at com.blahblah.controller.administrativo.memorando.MemorandoSaidaBean.actionImprimirMemo(MemorandoSaidaBean.java:92)
        at com.blahblah.controller.administrativo.memorando.MemorandoSaidaBean_ClientProxy.actionImprimirMemo(Unknown Source)
        at java.base@21.0.5/java.lang.reflect.Method.invoke(Method.java:580)
        at org.apache.el.parser.AstValue.invoke(AstValue.java:253)
        at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
        at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:67)
        at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:54)
        at jakarta.faces.component.UICommand.broadcast(UICommand.java:65)
        at jakarta.faces.component.UIData.broadcast(UIData.java:1541)
        at jakarta.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1245)
        at jakarta.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:426)
        at jakarta.faces.component.UIViewRoot._process(UIViewRoot.java:1717)
        at jakarta.faces.component.UIViewRoot.processApplication(UIViewRoot.java:927)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:43)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:172)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:125)
        at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:223)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:63)
        at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:67)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:133)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:65)
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:247)
        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:111)
        at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:108)
        at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
        at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
        at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$9$1.call(UndertowDeploymentRecorder.java:645)
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:152)
        at io.undertow.server.handlers.PathHandler.handleRequest(PathHandler.java:91)
        at io.undertow.server.handlers.CanonicalPathHandler.handleRequest(CanonicalPathHandler.java:49)
        at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$1.handleRequest(UndertowDeploymentRecorder.java:126)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:284)
        at io.undertow.server.DefaultExchangeHandler.handle(DefaultExchangeHandler.java:18)
        at io.quarkus.undertow.runtime.UndertowDeploymentRecorder$5$2.run(UndertowDeploymentRecorder.java:445)
        at java.base@21.0.5/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
        at java.base@21.0.5/java.util.concurrent.FutureTask.run(FutureTask.java:317)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:635)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:11)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:11)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base@21.0.5/java.lang.Thread.runWith(Thread.java:1596)
        at java.base@21.0.5/java.lang.Thread.run(Thread.java:1583)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:896)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:872)
Caused by: net.sf.jasperreports.engine.JRException: Input stream not found at: fonts/fontsfamily1723135526544.xml.
        at net.sf.jasperreports.repo.RepositoryUtil.getInputStreamFromLocation(RepositoryUtil.java:175)
        at net.sf.jasperreports.engine.fonts.SimpleFontExtensionHelper.loadFontExtensions(SimpleFontExtensionHelper.java:184)
        ... 76 more

Are custom font extensions not supported or must I do something I missed? The extension is a .jar file added to a local Maven repository. The missing file fonts/fontsfamily1723135526544.xml is inside this .jar.

Thanks in advance!

melloware commented 3 weeks ago

@redddcyclone we have a bunch of font integration tests passing in native. Can you decribe exactly what you are doing I don't see fonts/fontsfamily1723135526544.xml inside jasperreports-fonts-7.0.1.jar ? Where are you seeing that file?

melloware commented 3 weeks ago

oh don't forget if you include your own font you need this line in your application.properties to pick it up.

quarkus.native.resources.includes=fonts/**

Our Integration Tests do that and they are passing native.

redddcyclone commented 3 weeks ago

@melloware this file is inside a custom font extension I generated using JasperReports Studio (it generates a custom .jar file with any fonts you specify), as shown in this page: https://community.jaspersoft.com/knowledgebase/best-practices/custom-font-font-extension/

So it's a custom .jar file I add in my project through a custom local Maven repo (I inject the .jar in the repository and add to the project via pom.xml). The added fonts are inside the .jar file.

melloware commented 3 weeks ago

yep see above we have an Integration test doing this

https://github.com/quarkiverse/quarkus-jasperreports/blob/main/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsFontResource.java

and passing

melloware commented 3 weeks ago

@all-contributors add @redddcyclone for testing

allcontributors[bot] commented 3 weeks ago

@melloware

I've put up a pull request to add @redddcyclone! :tada:

redddcyclone commented 3 weeks ago

I'm trying a new build with quarkus.native.resources.includes=fonts/**. I'll report results soon

melloware commented 3 weeks ago

Thanks! let me know because I am using a custom Lobster font and DejaVu font and it creates this PDF with embedded fonts in Native mode: fonts.pdf

melloware commented 3 weeks ago

I submitted a PR to have the extension do this automatically since that is Jasper's recommended directory and examples.

redddcyclone commented 3 weeks ago

@melloware thanks a lot, this setting fixed my problem! Now my custom font extension is working fine.

Now a bit off-topic, I'm getting problems generating a report with barcodes (using Barcode4J). I'm getting these errors:

10:56:46,634 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] java.awt.Component.x: java.lang.NoSuchFieldError: java.awt.Component.x

10:58:46,153 SEVERE [org.primefaces.application.exceptionhandler.PrimeExceptionHandler] Could not initialize class org.apache.batik.bridge.CursorManager: java.lang.NoClassDefFoundError: Could not initialize class org.apache.batik.bridge.CursorManager

Should I open a new issue for this?

melloware commented 3 weeks ago

Ahh I have a Barcode4J native test as well: https://github.com/quarkiverse/quarkus-jasperreports/blob/main/integration-tests/src/main/java/io/quarkiverse/jasperreports/it/JasperReportsBarcode4JResource.java

Can you open a new ticket and try and reproduce it? My test is passing and prints out all Barcodes in a PDF.

melloware commented 3 weeks ago

@all-contributors add @redddcyclone for bug

allcontributors[bot] commented 3 weeks ago

@melloware

I've put up a pull request to add @redddcyclone! :tada: