我在将SUBREPORT_DIR
路径传递给我的子报告时遇到问题。这些报告实际上在同一个文件夹中,但在一个 JAR 文件中。我试过这样的事情(可能不准确):
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: Resource not found at : ...
在生成报告时得到。我怎样才能使这项工作?
编辑:
我试图在没有 的情况下定义我的子报表SUBREPORT_DIR
,但没有运气:
<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>