I can open a pdf when in development mode passed to an anchor as shown below
byte pdfByteArray = JasperExportManager.exportReportToPdf(jasperPrint);
setPdfStreamResource(new StreamResource(“tables.pdf”, () → new ByteArrayInputStream(pdfByteArray)));
anchorBillingOp.setHref(getPdfStreamResource());
UI.getCurrent().getPage().executeJs(“$0.click()”, anchorBillingOp);
But after compilation in production mode I get a nullPoinerException
Caused by: java.lang.NullPointerException
at java.base/java.net.URL.(URL.java:585)
… 133 more
net.sf.jasperreports.engine.JRException: java.net.MalformedURLException
What could be wrong
marcoc_753
(Marco Collovati)
December 29, 2023, 7:18pm
2
Please, post the complete stack trace
marcoc_753
(Marco Collovati)
December 29, 2023, 7:23pm
4
It seems JasperReports is not able to load the JRXML definition.
marcoc_753
(Marco Collovati)
December 29, 2023, 7:24pm
5
Where do you store it and how do you load it?
resources.META-INF.resources.assets
InputStream resourceAsStream = VaadinServlet.getCurrent().getServletContext()
.getResourceAsStream(“/assets/IPCORPORATE.jrxml”);
marcoc_753
(Marco Collovati)
December 29, 2023, 7:51pm
8
Do you have some reference to subreports or other resources inside the JRXML?
there is a parameter logo but it’s stored inside resources.META-INF.resources.img
marcoc_753
(Marco Collovati)
December 29, 2023, 8:12pm
11
Looks good. How is the application packaged? Is it a WAR deployed on a Servlet Container or a Spring Boot fat-jar?
marcoc_753
(Marco Collovati)
December 29, 2023, 8:17pm
12
My guess is that in production the JRXML resource is not found, resulting in a null inpustream
Its a war file. Am trying to change the jasperreports version
Not found, have I not placed it in the right folder in assets?
marcoc_753
(Marco Collovati)
December 29, 2023, 8:37pm
15
is the produced WAR, where is the JRXML file located? Is it in a jar inside the WEB-INF/lib or under WEB-INF/classes/?
WEb-INF/classes/META-INF/resources/assets
I would recommend to use the spring way of loading resources, this takes care of all different types of deployment and jar/war structures https://www.baeldung.com/spring-classpath-file-access
marcoc_753
(Marco Collovati)
December 29, 2023, 8:57pm
18
And if it is not a Spring application, I suppose you have to use getResourceAsStream("/META-INF/resources/assets/IPCORPORATE.jrxml")
IIRC, /META-INF/resources is resolved only for resources in JAR files (but I may be wrong)
My eyes saw spring in the stack trace
marcoc_753
(Marco Collovati)
December 29, 2023, 9:04pm
20
My eyes see little normally and even less at this hour