1

I'm creating a small web app, that will generate and generate a pdf file. The app is created with SpringBoot 2.5.4.

My first intent use this line to compile the jasper report

JasperReport compileReport = JasperCompileManager.compileReport(new FileInputStream("src/main/resources/Invoice.jrxml")); 

Everything works fine within the IDE (STS 4.x), but when I "build" and run with java -jar, I get a FileNotFoundException.

Then I decided to compile the .jrxml and use .jasper file. And also I want to move my files to /resources/static/reports folder, to allow the package to include that files.

But again I'm stuck, I want to retrieve static files within SpringBoot app, and when I run it, no matter how... I could load and read that file.

What I'm doing wrong?

Best Regards

0

1 Answer 1

1

A FileInputStream reads input bytes from a file in a file system – it won't let you access a file that is contained in a compressed JAR. Instead you could do the following:

getClass().getResourceAsStream("/Invoice.jrxml"); 

This should work if your file is contained in src/main/resources.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I think my error was that I created a folder "reports" inside static folder, and the correct place was in "resources". The with lines i got it... String reportFilename = "/reports/invoice.jasper"; InputStream is = getClass().getResourceAsStream(reportFilename); System.out.println(is.toString()); JasperReport jcReport = (JasperReport) JRLoader.loadObject(is);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.