4
votes

I'm working with iReport 3.5.0, and I'm using a subreport inside my main report. I don't want to give the absolute path for the subreport expression, but for example if I just give "bpSubReport.jasper" as the subreport expression (because sub and main are in the same directory), then iReport can find bpSubReport.jasper and compile the main report into bPReport.jasper, but my Java (gwt) application can't. It throws the exception

net.sf.jasperreports.engine.JRException: Could not load object from location : bpSubReport.jasper

Can you help me on how to give a relative path for the subreport and let the Java app. find it as well? Thanks.

3

3 Answers

4
votes

Well I got an answer.

You can't. You can't use relative paths for your subreports. You may try to compile the .jrxml files at runtime or something, but relative paths don't seem to work for the projects with external servers or file systems.

2
votes

You can use:

Map paramater = new Hasmap();
paramater.put("SUBREPORT_DIR",source);// source is path your subreport
1
votes

Keep all your jrxml in reports folder under resources(in classpath).

Parameter created :

<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["reports/"]]></defaultValueExpression>
    </parameter>

Subreport Element created:

<elementGroup>
                <subreport>
                    <reportElement uuid="60c50685-03c7-452b-b37a-dda4a2092d18" positionType="Float" mode="Transparent" x="15" y="567" width="517" height="200" isRemoveLineWhenBlank="true" backcolor="#FFFFFF"/>
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(yourList)]]></dataSourceExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "your_subreport.jasper"]]></subreportExpression>
                </subreport>
            </elementGroup>