Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Referencing an image in Jasper Report

 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Eugene Abarquez
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic