-3

I have javafx application that print to pdf. I works fine on linux (UBUNTU 20.04)

But when I run It On WIndow I get

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)
        at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1724)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Node.fireEvent(Node.java:8792)
        at javafx.scene.control.Button.fire(Button.java:203)
        at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
        at com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
        at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:3897)
        at javafx.scene.Scene.processMouseEvent(Scene.java:1878)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2623)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:557)
        at com.sun.glass.ui.View.notifyMouse(View.java:943)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:77)
        at jdk.internal.reflect.GeneratedMethodAccessor170.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:275)
        at com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:84)
        at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1852)
        ... 50 more
Caused by: java.lang.ExceptionInInitializerError
        at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:114)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:82)
        at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:251)
        at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:272)
        at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:156)
        at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:145)
        at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:758)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:1074)
        at com.sample.service.TransService.printTrans(TransService.java:473)
        at com.sample.service.TransService.saveTrans(TransService.java:298)
        at com.sample.service.TransService$$FastClassBySpringCGLIB$$c1f7da87.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
        at com.sample.service.TransService$$EnhancerBySpringCGLIB$$860dd8c4.saveTrans(<generated>)
        at com.sample.service.TransService$$FastClassBySpringCGLIB$$c1f7da87.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at com.sample.service.TransService$$EnhancerBySpringCGLIB$$861491a6.saveTrans(<generated>)
        at com.sample.controller.MainController.handleTrans(MainController.java:583)

I have included jaspter report maven dendencies

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

The error comes from when this line of code is excuted

JasperReport jasperReportInstance = session.getJasperReportInstance();

JasperPrint print = JasperFillManager.fillReport(jasperReportInstance, parameters, new JREmptyDataSource());

When I call fill report I get the error On on window

I am using java 17 oracle jdk jafax 17.0.1.

Any on with idea?

MT0
  • 143,790
  • 11
  • 59
  • 117
Navigator
  • 2,871
  • 4
  • 17
  • 27
  • 2
    [mcve] please, including the complete stacktrace .. where is the relation to javafx? – kleopatra May 31 '22 at 09:13
  • If you format the trace and code [as code](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) rather than quoted, it is easier to read. – jewelsea May 31 '22 at 09:47
  • Added Full Stack Trace @kleopatra – Navigator May 31 '22 at 10:34
  • Do you need to [“recompile from source JRXMLs”](https://community.jaspersoft.com/jasperreports-library/issues/11081). Try creating a small plain Java app without JavaFX and see if you can create a report. – jewelsea May 31 '22 at 11:02
  • I have found the issue. In Linux this works JasperReport jasperReport = (JasperReport) JRLoader.loadObject(getClass().getResourceAsStream("/com/sable/inv.jasper")); IN Windo The Paths Doesn't work. How Can I resolved This FOr Both Platform? – Navigator May 31 '22 at 12:05
  • The resolution of resources isn't really platform-dependent as far as I am aware. So, I don't see a reason for the lookup to work on one platform but not another. Review [resource lookup in JavaFX](https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other) and follow the suggestions in the troubleshooting section, that may or may not help you. – jewelsea Jun 02 '22 at 20:51

1 Answers1

0

I fixed the issue. The issue was my jasper report was using custom font which was not found when load the report. I tried to use build in jasper report font if you have included jasperreports-fonts. Go to jar and find fonts.xml replace font name you were using with the default one. Compile .jrxml and run jasper report

There were no issues with URL in the class path. If your report where in

src/main/resource/reports/customer.jaspper

Then Print that report I used

 JasperPrint print = JasperFillManager.fillReport(ClassLoader.getSystemResourceAsStream("reports/customer.jasper"), parameters, new JREmptyDataSource());

The solution works well also when running from jar

I hope will help someone.

Navigator
  • 2,871
  • 4
  • 17
  • 27