5

It's drives me crazy.. Last hour I am trying to figure out why my report stopped to worked right after I added a subreport to it.. I already checked and tried all similar issues here, here and here. Without success.. Subreport is in the same directory for sure.. The definition looks like:

<subreport isUsingCache="false">
                <reportElement uuid="db816b3c-a13d-440f-a6a2-f899762e61e4" x="0" y="89" width="555" height="100"/>
                <subreportParameter name="footerAddress">
                    <subreportParameterExpression><![CDATA[$P{footerAddress}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerManager">
                    <subreportParameterExpression><![CDATA[$P{footerManager}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerContact">
                    <subreportParameterExpression><![CDATA[$P{footerContact}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="footerBank">
                    <subreportParameterExpression><![CDATA[$P{footerBank}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[$P{SUBREPORT_DIR}]]></subreportExpression>
            </subreport>

Where $P{SUBREPORT_DIR} is "/valid/path/sub.report.jasper"

And I still getting an error: Resource not found at /valid/path/sub.report.jasper

WHY??

Community
  • 1
  • 1
nKognito
  • 6,297
  • 17
  • 77
  • 138

4 Answers4

9

In first message author says:

Where $P{SUBREPORT_DIR} is "/valid/path/sub.report.jasper"

$P{SUBREPORT_DIR} is a directory, but not a filename. It is the first error.

The second: sometimes jasper can't find subreport, even the path is correct.

The way for solving this problem:

  1. Pass $P{SUBREPORT_DIR} into main report (In this case: "/valid/path/"), put this parameter into a HashMap<String, Object> - standard way pass parameters into jasper.
  2. Pass $P{SUBREPORT_DIR} from main report into subreport as parameter: $P{SUBREPORT_DIR} main report -> $P{SUBREPORT_DIR} of subreport (this way used when exist subsubreport, which calling from subreport)
  3. In main report set expression to subreport as $P{SUBREPORT_DIR} + "sub.report.jasper"
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
sanBez
  • 933
  • 1
  • 8
  • 18
  • `$P{SUBREPORT_DIR} is a directory, but not filename. It is first error.` - Yes, the name of parameter is wrong (the value is not a folder name). But you can give any name you wants. Why it is an error? – Alex K Sep 09 '13 at 15:57
  • I am not exactly wrote. It is potential error. Jasper search subreports in $P{SUBREPORT_DIR} path. Therefore it is better define this parameter as a directory. – sanBez Sep 10 '13 at 06:13
  • 1
    The *JR* engine doesn't know about `$P{SUBREPORT_DIR}`, it is not built-in parameter. – Alex K Sep 10 '13 at 07:59
  • Wow! You are right. iReport generate this parameter when subreport creating. I use it so often that I did not even think about it :) So, it is my religion to use directory :) But this really useful. For instance, this described in second item of my message – sanBez Sep 10 '13 at 08:35
  • @lealceldeiro . Thanks, man. I had the same problem and I solved it. you really helped me – Aliasghar Yaghoobzadeh Apr 22 '21 at 16:45
1

I had this issue earlier. My approach was - i was sending the absolute folder in a parameter say folder_path .And then in the sub-report expression i was using
new File(($P{folder_path} + "*.jasper" ) .
this *.jasper file can be replace by "\\inner_folder\\*.jasper". And this worked perfectly

cjava
  • 656
  • 1
  • 8
  • 22
0

This happens to me from time-to-time, and its always been a platform OS that is the key deciding factor of why some code works, and others doesnt. However what has always worked was relative references instead of absolute references.

My suggestion would be if cjava's solution doesnt work, is to find out what JasperReports is doing on Disk. Depending on your platform, *nix, Windows, You may need to figure out what system calls JasperReports is running to find the path it is using. In my application I found that even though I was specifying a path-less reference that worked before, some platforms would path search differently and fail to find the report.

Some other questions on how to troubleshoot System calls:

*nix - Strace

strace java applet

Windows - Process Monitor

On Windows, how can I find what files a given process is using? Is there software that does this?

Mac - DTruss

ltrace equivalent for osx?

Good Luck.

Community
  • 1
  • 1
Israel Lopez
  • 1,135
  • 3
  • 11
  • 25
0

try to send SUBREPORT_DIR parameter from code. Maybe it is missing... if you use maven, check resource directory tag in pom.xml and compare them.

params.put("SUBREPORT_DIR", "reports/report/blablaFolder/");
StarCrafter
  • 451
  • 5
  • 12