How to access a .jrtx template file from a Jasper report (.jrxml)?

I use this example to apply a jasper template to a jasper report. I cannot find out how I can reference the jasper template from the .jrxml file. The .jrxml file and .jrtx are in the same place. In Jasper, I mean a template using the following syntax.

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
              name="QCReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20"
              topMargin="20" bottomMargin="20" uuid="0ea707c5-78f5-4f37-a065-a228202cb59e">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <import value="org.apache.commons.lang.StringUtils"/>
    ..
    <template><![CDATA["JasperCustomStyle.jrtx"]]></template>
    ..

But that gives me an exception Byte data not found at: JasperCustomStyle.jrtx.. Can someone please help me figure out how to access the jasper template from a .jrxml file?

Detailed exception

Caused by: net.sf.jasperreports.engine.JRException: Byte data not found at: JasperCustomStyle.jrtx.
    at net.sf.jasperreports.repo.RepositoryUtil.getBytesFromLocation(RepositoryUtil.java:210)
    at net.sf.jasperreports.engine.xml.JRXmlTemplateLoader.loadTemplate(JRXmlTemplateLoader.java:106)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.loadTemplate(JRFillReportTemplate.java:111)
    at net.sf.jasperreports.engine.fill.JRFillReportTemplate.evaluate(JRFillReportTemplate.java:89)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.collectTemplates(JRBaseFiller.java:740)

The jrtx file is as follows.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jasperTemplate PUBLIC "-//JasperReports//DTD Template//EN" "http://jasperreports.sourceforge.net/dtds/jaspertemplate.dtd">

<jasperTemplate>
    <style name="New style" mode="Opaque" forecolor="#000000" backcolor="#FFC800" fill="Solid" hAlign="Center" vAlign="Middle" isBold="true" isUnderline="true">
        <box>
            <topPen lineWidth="1.0"/>
            <leftPen lineWidth="1.0"/>
            <bottomPen lineWidth="1.0"/>
            <rightPen lineWidth="1.0"/>
        </box>
    </style>
</jasperTemplate>
+4
source share
1 answer
Caused by: net.sf.jasperreports.engine.JRException: Byte data not found at: JasperCustomStyle.jrtx.

which means the template was not found .

, ,

<template>$P{templateLocation} + "JasperCustomStyle.jrtx"</template>
<parameter name="templateLocation"/>

templateLocation , ( /)

URL ( -)

<template class="java.net.URL">$P{templateURL}</template>
<parameter name="templateURL" class="java.net.URL"/>

templateURL URL- , - , , URL-

+5

Source: https://habr.com/ru/post/1652927/


All Articles