Java JasperReports:找不到子报表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18656016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 09:54:24  来源:igfitidea点击:

JasperReports: Can't locate subreport

javaspringjasper-reportsireport

提问by nKognito

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, hereand 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"

$P{SUBREPORT_DIR} 在哪里 "/valid/path/sub.report.jasper"

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

我仍然收到错误: Resource not found at /valid/path/sub.report.jasper

WHY??

为什么??

采纳答案by sanBez

In first message author says:

在第一条消息中,作者说:

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

$P{SUBREPORT_DIR}/valid/path/sub.report.jasper”在哪里

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

$P{SUBREPORT_DIR}目录,但不是文件名。这是第一个错误。

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

第二种:有时jasper找不到子报表,即使路径正确。

The way for solving this problem:

解决这个问题的方法:

  1. Pass $P{SUBREPORT_DIR}into mainreport (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 mainreport into subreportas 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"
  1. 传递$P{SUBREPORT_DIR}报告(在这种情况下:“ /valid/path/“),把这个参数为HashMap<String, Object>-标准的方式传递参数到碧玉。
  2. 通过$P{SUBREPORT_DIR}从主报告到报表的参数:$P{SUBREPORT_DIR}主报告- >$P{SUBREPORT_DIR}子报表(使用这种方式时存在subsubreport,从报表调用)
  3. 在主报表中将子报表的表达式设置为$P{SUBREPORT_DIR}+ " sub.report.jasper"

回答by cjava

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

我之前有这个问题。我的方法是 - 我在参数中发送绝对文件夹说 folder_path 。然后在我使用的子报告表达式中
new File(($P{folder_path} + "*.jasper" )
这个 *.jasper 文件可以替换为"\\inner_folder\\*.jasper". 这工作得很好

回答by Israel Lopez

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.

我的建议是,如果 cjava 的解决方案不起作用,那就是找出 JasperReports 在磁盘上做什么。根据您的平台、*nix、Windows,您可能需要弄清楚 JasperReports 正在运行哪些系统调用才能找到它正在使用的路径。在我的应用程序中,我发现即使我指定了一个以前有效的无路径引用,一些平台也会以不同的方式进行路径搜索并且无法找到报告。

Some other questions on how to troubleshoot System calls:

关于如何对系统调用进行故障排除的其他一些问题:

*nix - Strace

*nix - Strace

strace java applet

strace java小程序

Windows - Process Monitor

Windows - 进程监视器

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

在 Windows 上,如何找到给定进程正在使用的文件?有没有软件可以做到这一点?

Mac - DTruss

Mac - DTruss

ltrace equivalent for osx?

等价于 osx 的 ltrace?

Good Luck.

祝你好运。

回答by StarCrafter

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

尝试从代码发送SUBREPORT_DIR参数。也许它丢失了......如果你使用maven,检查pom.xml中的资源目录标签并比较它们。

params.put("SUBREPORT_DIR", "reports/report/blablaFolder/");