Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Referencing an image in Jasper Report

 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic