Image expression URL in Jasper Reports

I would like to embed an image into my JasperReports jrxml file. I have this directory structure.

Tomcat Root
 webapps
  reports
   -->images
    --> company_logo.jpg
   -->reports
    -->sample.jasper
   -->WEB-INF
    -->classes

And I tried doing this thinking that this is relative to my reports context root

<image>
 <reportElement x="0" y="0" width="104" height="40"/>
 <imageExpression class="java.lang.String">
  <![CDATA["images/company_logo.jpg"]]>
 </imageExpression>
</image>

..and this also

<image>
 <reportElement x="0" y="0" width="104" height="40"/>
 <imageExpression class="java.lang.String">
  <![CDATA["/images/company_logo.jpg"]]>
 </imageExpression>
</image>

but it always says there was an error loading bytes from location JRLoader.

I tried doing this and it works, but I am a bit confused why my first two attempt doesn't.

Is this really how you embed images in JasperReports? Do you need to supply the whole path? I am thinking that there should be a page relative что-то.

<image>
 <reportElement x="0" y="0" width="104" height="40"/>
 <imageExpression class="java.lang.String">
  <![CDATA["http://localhost:8080/reports/images/company_logo.jpg"]]>
 </imageExpression>
</image>

Я немного озадачен правильным путем.

22
задан halfer 8 November 2017 в 23:10
поделиться