*
The moose likes Other Open Source Projects and the fly likes Referencing an image in Jasper Report Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Referencing an image in Jasper Report" Watch "Referencing an image in Jasper Report" New topic
Author

Referencing an image in Jasper Report

Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Hello,

I have a question regarding how to reference an image file in your jrxml file. What I have basically is a web application which exports reports in other formats, and the reports should include a logo of the company. My jrxml file contains an <image/> element with an <imageExpression/> that points to the company logo file. My problem is I keep getting a exception when I run my application.

I am referencing the image file as follows:


The image file is located inside the "images" folder by the way and the jasper files inside the "reports" folder. I am thinking this might be a problem with the context path, but I have no idea how to correctly reference it from inside the jrxml file.

Please advice.

Eugene


There's so much to learn in this industry, and not everybody has the necessary interest.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
What happens if you try:



The image has to be in the classpath -- I'm not sure if your /images folder is in the classpath or is a directory on the root of the machine, but this way you can manage it yourself (by placing it in the classpath)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Hi Joel,

Thanks for the quick reply.

My "images" folder is located at the root of my war file. The directory of my web app is as follows:



This might sound like a dumb question, but I will ask it anyway. Can you elaborate on what you mean by placing the images folder in the classpath?

Thanks.

Eugene
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
Try placing the images you need for your report in an images folder underneath the classes folder:



The classpath the the path from which Java loads classes and resources (like images). The root of the webapp is not typically in the classpath (so you can't access anything in the images directory via Java code without jumping through some hoops). But the WEB-INF/classes directory is in the classpath, so you can place resources underneath it for easy access.
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Hi Joel,

Thanks you've been very helpful. I finally had it working. I placed the logo file in the classpath like you said and moved the "reports" folder, which contains my ".jasper" files, inside the "WEB-INF" lib (it doesn't seem to work when I place it in the root of my webapp as I did beforte). As a reference to those who might bump into the same issue, my diretory structure now looks like this:



Thanks a lot! Cheers!





Eugene
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
As an aside, you should put the reports/demoreport.jasper underneath the WEB-INF/classes directory as well, as the WEB-INF/lib is usually reserved for .jar files (it surprises me a just a little bit that having the .jasper file underneath lib worked -- I would have assumed that the webserver only loaded .jars from the lib directory.)
Eugene Abarquez
Ranch Hand

Joined: May 18, 2006
Posts: 211
Oh I mean under the "WEB-INF library" not the sub-folder "lib". I placed it inside a "reports" subfolder: "WEB-INF/reports". See the directory above.

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 580
The point is I can't set the classpath on the client's machine when deploying.
How can I avoid setting the classpath in that machine?
Thanks
Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Referencing an image in Jasper Report
 
Similar Threads
Image problem in Jasper reports
[Jasper Report] Can't render image
Jasper Report and JAR file
Image Display problem in jasper report
Struts2 + JasperRepots: Problem with relative path!