title: How to show an image on jasper report?
body: <p>I want to show an image on a jasper report. I have the following on the .jrxml:</p>
  
  <pre><code>&lt;image&gt;
    &lt;reportElement x="181" y="0" width="209" height="74"/&gt;
    &lt;imageExpression class="java.lang.String"&gt;&lt;![CDATA["logo.jpg"]]&gt;&lt;/imageExpression&gt;
  &lt;/image&gt;
  </code></pre>
  
  <p>The image logo.jpg is in the same directory as the .jrxml. By just putting that it didn't work for me. I googled a bit and found out that jasper report considers what i put on the .jrxml as a relative path to the JVM directory and that to change this I need to pass as a "REPORT_FILE_RESOLVER" parameter a FileResolver that returns the file. So, I did the following in my .java (is located in same place as the .jrxml and the image)</p>
  
  <pre><code>FileResolver fileResolver = new FileResolver() {
  
   @Override
   public File resolveFile(String fileName) {
    return new File(fileName);
   }
  };
  HashMap&lt;String, Object&gt; parameters = new HashMap&lt;String, Object&gt;();
  
  parameters.put("REPORT_FILE_RESOLVER", fileResolver);
  ...
  </code></pre>
  
  <p>Which should return the expected file, but I still get a </p>
  
  <pre><code>net.sf.jasperreports.engine.JRException: Error loading byte data : logo.jpg
      at net.sf.jasperreports.engine.util.JRLoader.loadBytes(JRLoader.java:301)
      at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:479)
      at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:180)
  ...
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks!</p>