views:

3212

answers:

4

The following .jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DTC-Campaigns-Block-Campaigns-Helper-Campaigns" language="groovy" pageWidth="794" pageHeight="450" orientation="Landscape" columnWidth="794" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <queryString><![CDATA[SELECT 1;]]></queryString>
    <detail>
     <band height="50" splitType="Stretch">
      <subreport>
                            <reportElement x="0" y="0" width="794" height="25"/>
       <subreportExpression class="java.lang.String"><![CDATA["./test.jasper"]]></subreportExpression>
      </subreport>
     </band>
    </detail>
</jasperReport>

won't compile within iReport 3.6.0:

Compiling to file... /home/dominik/workspace/project1/reporting/MyFile.jasper
Compiling subreports....
Unable to locate the subreport with expression: "$P{SUBREPORT_DIR} + "test.jasper"".

Even fixing SUBREPORT_DIR to ./ won't help, neither will compiling test.jrxml manually before the master report.

Any ideas?

A: 

Can't you determine the current directory and pass it in as a parameter? That's how I'm doing it and it works quite well. If you are integrating Jasper Reports into code you can even use some code to get the full path of the current directory in Java and pass it in through a HashMap.

sventech
Well, I didn't even start it from my own Java application but from within iReport.
DaDaDom
You can set a default for the parameter, and prompt the user to change it if necessary. Jasper seems to be set up to use only a _full_ path, not a relative path (<code>./foo</code>) as you are trying. Relative paths are a bit more convenient, but should only be strictly necessary when integrated in a program, where you can determine the full path from the relative path anyway.
sventech
A: 

In the jrxml extract, you do not specify that SUBREPORT_DIR is a String parameter... You might add this information.

I also notice a change of behaviors between version 3.5.2 and 3.5.3 Changelog of version 3.5.3 says :

Automatic compilation of subreports

As a consequence parametrize subreport path do not seems to work any longer... (but I remembered getting a warning, and not a fail).

Have you tried :

  • To compile only the subreport (using iReport). [a preview will produce the jasper file which is the compiled version of the jrxml]
  • To give an expression with the jrxml file (instead of the jasper file) $P{SUBREPORT_DIR} + "test.jrxml", and without a parameter at all (like "test.jrxml" -- your subreport needs to be in the same local directory as your main report)
Jmini
A: 

Hi man,

To solve this problem, you have to set the absolute path in the $P{SUBREPORT_DIR}.

It can be done in iReport in the Properties windows, in the attribute "Default Value Expression".

For a better explanation, see: http://jasperforge.org/plugins/espforum/view.php?group_id=83&amp;forumid=101&amp;topicid=62793

ezmarques
But that only works if the report is always compiled within the same directory structure. What if I create the report on my local machine and move it over to a server for further processing later on? Anyway, for now I simply put all source files into one folder.
DaDaDom
A: 

you don't need to include SUBREPORT_DIR in subreport... As long as supreport is in the same directory like in main report.. there would be no problem...compilation occurs when you preview the jrxml file...

jhen
But what if they aren't in the same directory - which usually is the cleaner structure?
DaDaDom