当路径指向JAR文件内时,将SUBREPORT_DIR传递给子报告[Jasper Reports 4.5] [英] Passing SUBREPORT_DIR to subreport when the path points inside a JAR file [Jasper Reports 4.5]

查看:184
本文介绍了当路径指向JAR文件内时,将SUBREPORT_DIR传递给子报告[Jasper Reports 4.5]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 SUBREPORT_DIR 路径传递到子报表时遇到问题。报告实际上位于同一文件夹中,但位于JAR文件中。我尝试过这样的事情(可能不准确):

I'm having problems passing the SUBREPORT_DIR path to my subreport. The reports are actually in the same folder, but inside a JAR file. I've tried something like this (might be inaccurate):

parameterList = new HashMap<String, Object>();

URL mainReport = this.getClass().getResource("mainReport.jasper");
String mainReportPath = mainReport.getPath();
String subreportDir = mainReportPath.substring(0, mainReportPath.lastIndexOf("/")+1);

parameterList.put("SUBREPORT_DIR", subreportDir);

此路径指向JAR文件,但我得到 net.sf。 jasperreports.engine.JRException:在报告生成时找不到资源:... 。我怎样才能做到这一点?

This path points inside the JAR file, but I get net.sf.jasperreports.engine.JRException: Resource not found at : ... upon report generation. How can I make this work?

编辑

我试图定义我的子报告没有 SUBREPORT_DIR ,但没有运气:

I tried to define my subreport without the SUBREPORT_DIR, but no luck:

<subreport>
      <reportElement x="0" y="32" width="475" height="17"/>
      <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{current})]]></dataSourceExpression>
      <subreportExpression><![CDATA["mysubreport.jrxml"]]></subreportExpression>
</subreport>


推荐答案

我的主要问题是,我使用的是自定义JAR装载机,Jasper不知道。好消息是,也可以将子报表作为 java.net.URL java.io.InputStream 传递:

My main problem was, that I was using a custom JAR loader, which Jasper didn't know of. The good news is it is also possible to pass a subreport as java.net.URL or java.io.InputStream:

Java代码:

InputStream subInputStream = this.getClass().getResourceAsStream("sub.jasper");
parameterList.put("SUBREPORT_INPUT_STREAM", subInputStream);

JRXML:

<subreportExpression class="java.io.InputStream"><![CDATA[$P{SUBREPORT_INPUT_STREAM}]]></subreportExpression>

这篇关于当路径指向JAR文件内时,将SUBREPORT_DIR传递给子报告[Jasper Reports 4.5]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆