4

I want to insert images in my jasper report ,swing application. All images are in one package. I want to set path for images in jasper report.That means, to set project images's paths.When the entire project location is changed, there is an exception saying no images found. Please let me know how to set the image paths.

Project structure: MyProject
|-Source Packages

under source package
|-Images // my images are in here
|-Reports // where my jasper reports are in
|-MyJFrames |

1
  • can you add more details like your project structure and exception ?
    – r0ast3d
    Nov 8, 2011 at 16:08

3 Answers 3

7

You haven't posted many particulars, but i have ran into a similar issue when dealing with absolute/relative paths with Jasper Report.

There is a known "discomfort" or a bug (if you want to call it that way) with Jasper Report not being able to set or use relative paths to your project resources (subreports, images etc) especially if you are compiling the reports with the IREPORT designer tool.

I am working with jasper report and IREPORT 4.1.1 and every time i compile the JRXML to a .jasper file, my paths are absolute. This causes "havoc" when the whole project is moved to a different machine. In order to use relative paths to my reports i have to compile the reports via programming means i.e in my Java application. In a nutshell, the java utility method i am using reads the JRXML file and substitutes the absolute path with a relative path and then compiles the report.

Take a look at this forum, which has some different answers of how to do it.

http://forums.devshed.com/java-help-9/relative-path-for-subreport-in-jasperreport-309313.html

6
  • I tried all those samples in my swing application. when the project is run in netbean, it works. but when the .jar is run, there is an exception net.sf.jasperreports.engine.JRException: Byte data not found at : C:\Users\Dhanu shka\file:\D:\Projects\MyBizProjects\fin\dist\SSM.jar!\Reports\background.png . also I tried sending the absolute path. but didn't work. please any one tell me how to do this in swing application
    – Débora
    Nov 8, 2011 at 21:06
  • 1
    @Aash Try placing the image folder on you classpath. The way it is described here: coderanch.com/t/63485/open-source/…
    – Mechkov
    Nov 8, 2011 at 21:11
  • Thanks, but in my swing application.. where my images might be in ? As forums.devshed.com/java-help-9/… ,and its first solution , I put my images in the same folder where .jasper located.but didn't work. I m new. Would you let me know more?
    – Débora
    Nov 8, 2011 at 21:29
  • Do your reports run outside of the IDE? If they do then, the JRXML and.jasper folder is on the classpath. You can put the images there in the first place.
    – Mechkov
    Nov 8, 2011 at 21:35
  • Yes, they run.earlier I kept images in same folder where .jasper located.When it runs with netbeans,it is ok. But when I run only jar,it doesn't work.(Earlier I tried without images and only texts.. it worked without the IDE)
    – Débora
    Nov 8, 2011 at 21:42
2

I also faced the same problem as you. To solve this, use a hard coded path value. You have to create one parameter to which you can pass your image location and then use this parameter in your image expression. I found solution in this post.

0

For Images and Subreport Path is required. I am using ./ in default prompt to work from any where i kept everything in single folder. SUBREPORT_DIR Required path same if location is different for different element then you have to pass though Parameter section as Above Post. Please check his link also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.