0

How do you handle jasper reports where the image path is different at runtime vs in the editor?

Here's an example:

I have a report definition in the folder /src/main/resources/reporttemplates/MyReport.jrxml

That report includes an image located at /src/main/resources/reporttemplates/images/MyImage.png

When referring to the image in the editor it appears to accept two different path types:

Either the absolute project path: "/src/main/resources/reporttemplates/images/MyImage.png" or or a relative path based on the report definition's directory: "images/MyImage.png"

However, at runtime the path needs to change. In my case, when the project is built and deployed to Tomcat, the path to the image needs to be relative to the web app's classes folder: "reporttemplates/images/MyImage.png".

Any tricks to make this work?

angrycrab
  • 830
  • 1
  • 9
  • 23

1 Answers1

0

Found a good solution to this problem:

When specifying the image's path, I can use: $P{image_path} + "/MyImage.png"

Then, all I need to do is set a default value for image_path that works in the editor (e.g. "/src/main/resources/reporttemplates/images" ). Finally, when running the report from the web app, I can specify a different path at runtime (e.g. "reporttemplates/images").

Source: http://www.oodlestechnologies.com/blogs/Using-Jasper-Reports-Part-5--(Adding--dynamic-path-to-images-in-jasper)

Alex K
  • 22,315
  • 19
  • 108
  • 236
angrycrab
  • 830
  • 1
  • 9
  • 23