Malformed URL Exception During Production Mode

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

Please, post the complete stack trace

message.txt (14.5 KB)

It seems JasperReports is not able to load the JRXML definition.

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”);

Do you have some reference to subreports or other resources inside the JRXML?

message.txt (23.2 KB)

there is a parameter logo but it’s stored inside resources.META-INF.resources.img

Looks good. How is the application packaged? Is it a WAR deployed on a Servlet Container or a Spring Boot fat-jar?

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?

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

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 :nerd_face::innocent:

My eyes see little normally and even less at this hour :man_facepalming: