无法从jrxml文件获取JasperReports属性

时间:2018-07-31 11:31:14

标签: jasper-reports

我遵循了this wiki article中的示例:

示例1,在jasperreports.properties文件中指定的值:

[CDATA[new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.band.split.type"))]]

所以我定义了变量:

<variable name="CrucialProperty" class="java.lang.String" resetType="Report" calculation="Nothing">
        <initialValueExpression><![CDATA[new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu"))]]></initialValueExpression>
        <variableExpression><![CDATA[new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu"))]]></variableExpression>
</variable>

但是,当尝试发布此类jrxml时,出现此错误:

07-31-18:13:16:15 [http-/0.0.0.0:8080-5] ERROR [ReportingServlet:paveljanicek] Problem processing servlet: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=13$
                                    <------------------------------------------->
2. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=14$
                                    <------------------------------------------->
3. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=13$
                                    <------------------------------------------->
4. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=14$
                                    <------------------------------------------->
5. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=13$
                                    <------------------------------------------->
6. net.sf.jasperreports.engine.util.JRProperties cannot be resolved to a type
                value = new String (net.sf.jasperreports.engine.util.JRProperties.getProperty("net.sf.jasperreports.extension.simple.font.families.dejavu")); //$JR_EXPR_ID=14$
                                    <------------------------------------------->
6 errors
.

我甚至尝试在jrxml文件的开头导入utils:

<import value="net.sf.jasperreports.engine.util.*" />

但未进行任何更改,无法发布jrxml。我究竟做错了什么?

1 个答案:

答案 0 :(得分:2)

如果我没记错的话,net.sf.jasperreports.engine.util.JRProperties类已被弃用很长时间,并且在两年前的6.2.2版本中被删除。

相反,请尝试:

net.sf.jasperreports.engine.JRPropertiesUtil.getInstance(
  $P{JASPER_REPORTS_CONTEXT}).getProperty(
    "net.sf.jasperreports.band.split.type")