JasperServer:无法找到子报告异常 [英] JasperServer: Unable to locate the subreport exception

查看:131
本文介绍了JasperServer:无法找到子报告异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了几天来解决这个错误没什么新问题。



我有一个报告,其中包含多级子报告,一切正常 iReport 3.7.5 。我使用 subreport.jasper 作为第一级&中的子报表表达式。另外 subreportA.jasper subreportB.jasper 在第二级&将所有(主报告和子报告)放在同一路径中。



当我尝试在我的 JasperServer上部署它时出现的问题
当我尝试上传第一个主报告时, iReport 向导提示我附加第一个 subreport.jrxml 在资源文件夹中,使用 repo:subreport.jrxml repo:subreport.jasper 进行访问。
然后我手动上传第二级子报表并执行相同的操作将子报表表达式更改为 repo:subreportA.jasper repo:subreportB .jasper



我遇到了编译错误:无法找到带有表达式的子报表:repo:subreport。碧玉。 java.lang.Exception:repo:找不到subreport.jrxml。



我尝试打解决方案但没有任何效果。
使用:SUBREPORT_DIR @开头,



使用完整路径: repo:/ Circuit_Reports / Connectivity / Connectivity_files /



.jasper &之间切换 .jrxml



在lib中使用 jasperserver_api_engine_impl_0_fix.jar 文件夹作为此bug的固定,



我还搜索了数据库记录,以确保它们位于同一文件夹中并具有相同的父文件夹。

解决方案

Longtalk之前的Smalltalk;)



(当然我不想鼓励你阅读这篇长篇详细文章的所有内容!大胆的标记可能已足以解决你的问题但我发现值得更详细地记录这些棘手的东西!)



因为我在这上面投入了几个小时(几周前我解决了之后,现在有了改变,但忘记了正确记录,忘了我是怎么做的,无法检索这些信息再次以任何形式 - 在上传和配置到/在JasperServer中时)...这里有一些关于子报告引用的各种网站上提到的聚合功能,如何它的工作原理和人们可以尝试的...



(如果有希望的话,我会更新我的或其他调查结果)



捷径详情/最佳实践?! 4



直到Jasper功能提供类似的包装解决方案本身...



解决与在预览模式下本地运行* .jrxml,* .jasper文件或在JasperServer上远程运行相关的所有问题我现在正在使用以下方法允许仅使用单个* .jrxml文件,在多开发人员环境中无需修改即可在本地和远程工作,支持每个环境独立重构dir结构(路径,名称)(=应该;-)):




  • 使用一些 jasper-utils - * .jar


    • 把它放进去在您的项目(Java)类路径中( 项目 - >属性 - > Java构建路径 - >库 - >添加

    • put它在 ../ jasperserver / WEB-INF / lib / 文件夹


  • 引用一些自定义的Jasper Java Scriptlet jr.utl.EnvScriptlet ,它会执行您的丑陋子报表路径/引用魔法主报告


    • 通过在主报告中添加属性来定义 REPORT_SCRIPTLET 报告属性 - >报告 - >数据集 - > Scriptlet类:jr.utl.EnvScriptlet


  • 使用一些自定义属性文件 jr.utl.properties 或以其他方式提供的系统属性(设置Java系统属性的任何其他方式都可以正常工作 - 已经设置属性的地方将覆盖已加载的文件属性)以配置不同的环境,包括




    • 当前环境通过 jr.utl.env 属性(prod,myOsUsrName,test,demo,staging,local,...)获取信息


      • 确定必须如何生成子报表引用/看起来像


    • 服务器子报告父目录属性引用

    • 取例如这些属性文件内容并在每个环境中放置一个:

    • 服务器上: ../ jasperserver / WEB-INF / classes / jr .utl.properties

        jr.utl.env = prod 
      mycompany.local.jr.gui.rep.subrep1.parentdir = repo:/ x / y / z /
      mycompany.local.jr.gui.rep.subrep2.parentdir = repo:/ x / y / z /
      mycompany.local.jr.gui.rep.subrep3.parentdir = repo:/ x / y / foobar /


    • 本地JasperSoft Studio(Eclipse)Java src /构建路径例如 ../ myrepproject / src / java / jr.utl.properties

        jr.utl.env = dietrian 
      mycompany.local.jr.gui.rep.subrep1.parentdir = D:/ reporting / src / reports /
      mycompany.local.jr.gui .rep.subrep2.parentdir = D:/ reporting / src / reports /
      mycompany.local.jr.gui.rep.subrep3.parentdir = D:/reporting/src/reports.otherdir/




      • 在我们的环境中实现源修改独立性我们参数化这些值并生成它们一次通过一些依赖于工作空间/用户特定的 local.properties 文件,基于这个想法:

         
        | - build.xml(包含ANT构建魔法)
        | - build.properties(包含全局属性)
        | - local.properties(在版本控制中忽略,例如.hgignore,用户特定于local.template.properties生成的)
        | - local.template.properties(生成local.p的ANT构建任务的源代码)上面的roperties)
        | - mycomp.local.proj.reporting.dir = D:/ reporting
        | - src / reports
        | - jr.utl.properties(在版本控制中被忽略,用户 - 特别是基于以下模板生成的)
        | - jr.utl.template.properties(ANT构建任务的源代码,生成上面的jr.utl.properties)
        jr.utl.env = $ {user。 name}
        mycompany.local.jr.gui.rep.subrep1.parentdir = $ {mycomp.local.proj.reporting.dir} / src / reports /
        mycompany.local.jr.gui.rep .subrep2.parentdir = $ {mycompany.local.jr.gui.rep.subrep1.parentdir}
        mycompany.local.jr.gui.rep.subrep3.parentdir = $ {mycomp.local.proj.reporting.dir } /src/reports.otherdir/




  • BASE_DIR 主报告参数定义为例如
    $ P {REPORT_SCRIPTLET} .getProp(mycompany.allsubreports.parentdir) (匹配<中某些与环境相关的属性) code> jr.utl.properties file)


  • 将主子报表表达式定义为例如 jr.utl.EnvScriptlet.getSubrepPath($ P {BASE_DIR},subrep1.jrxml)


    • 自动解析您也可以使用的属性中的值,例如这些变体:


      • jr.utl.EnvScriptlet.getSubrepPathByPropKey($ P {BASE_DIR},mycompany.local.jr.gui。 rep.subrep1.name)

      • jr.utl.EnvScriptlet.getSubrepPathByPropKeys(mycompany.local.jr.gui.rep。 subrep1.parentdir,mycompany.local.jr.gui.rep.subrep1.name)


    • $ P {REPORT_SCRIPTLET} .getSubrepPath(...)在这里不起作用:-((我不知道为什么)


  • 当您将所有文件放在服务器上时,不要忘记重新启动服务器



4 :当然我仍然看到一些小的改进,但它似乎比我迄今发现的所有丑陋的解决方案要好得多。改进我会请参阅:




  • 使用 REPORT_SCRIPTLET 或scriptlet功能可能不是最好的方法go,但它可能适用于绝大多数用例

  • 虽然两个现有的Jasp er类表明他们似乎无法正确处理上述问题:




5 :相关的特殊处理在此编码: EnvScriptlet.java/getSubrepPath(String,String, boolean,String [])



简介(背景)



首先要知道的是JasperStudio中的处理/设置 Jasper Server(存储库) 5 的处理完全相差。 。



假设我们有以下内容环境:




  • 我们的Eclipse安装目录: C:\ eclipse \

  • 我们的Eclipse(报告)工作区: C:\ workspace \

  • 我们的报告项目在: C:\ workspace \ _report-project \

  • 我们的报告在: C :\ workspace \ report-project \src / reports

  • 主报告 C:\ workspace \ report- project \src / reports / masterrep.jrxml

  • 一些子报告 C:\ workspace \ _report-project \src / reports / subrep1.jrxml

  • 另一个子报告 C:\ workspace \report-project \src / reports / somesubdir / subrep2 .jrxml

  • 我们的工作区主报告中的 BASE_DIR (在下一节中进行了解释)设置为 C:\ workspace \ report-project \src / reports /

  • 我们的Jasper Report Server GUI repo id-path of our主报告将是: / x / y / z /
    (不要与视觉命名路径混淆,例如可能财务报告/费用/当前年度



一般来说: Jasper Studio,JasperServer



(以及其他Jasper运行时环境,如自定义Java Jasper包使用):




  • 声明报告参数前缀似乎是良好做法,这取决于您的Jasper运行时环境,例如名为 BASE_DIR


    • 这里重要的是假设可能包含后缀 / 1 ,因为有些情况下您可能/想要使用它的方式应该是空的或未删节的路径表达式


      • 例如 $ P {BASE_DIR} +subrep1.jrxml哪个应解析为
        repo:subrep1.jrxml


    • 见例如此处了解更多详情(查找 SUBREPORT_DIR




1 :其中在处理类似目录的结构时,我个人总体上发现了一个不好的做法(在这方面没有看Jasper Reports)



JasperStudio Designer(Eclipse插件)



(具有更多功能的官方IReport继任者)



(如果您不使用预览功能,则可能是对你不感兴趣)




  • 遗憾的是,我发现没有切实可行的方法来完全支持(正常)子团队开发与子报告(可能还有其他亲戚)资源以及),这里的意思是(目前我不知道)不可能分离本地路径和* .jrxml文件 :-(


    • 例如,如果你有一个版本控制系统d在不同的环境(不同的本地路径到repos和/或不同的开发人员)工作主报告必须以某种方式包含子报告的本地路径


      • 我尝试了不同的失败方法:

      • BASE_DIR 中的相对路径表达式因工作原因无效目录是eclipse目录,例如 C:\ eclipse

      • Eclipse-> Window-> Preferences-> JasperStudio-> ;属性 - >添加例如 my.base.dir


        • 它在预览模式下不可用,例如通过 new java.io.File(System.getProperty(my.base.dir))。getCanonicalPath()+/我们的 BASE_DIR 表达式(这些道具可能仅由设计师自己使用,但未在预览运行中设置)


      • 以防您偶然发现(如我所做): Eclipse-> Window-> Preferences-> JasperStudio->报告执行 - > Virtualizer临时路径是不相关的(在这里没用)处理报告结果的存储缓存

      • 当然我可以编写一个ANT任务来替换基于regexp过滤器副本的这些本地模式在每次使用/结账时,但这似乎不是处理这个问题的好方法



  • 如果您只想使用 * .jrxml 文件(因为我做 3 ),您必须参考一些 subrep1.jrxml 像这样: net.sf.jasperreports.engine.JasperCompileManager.compileReport($ P {BASE_DIR} +subrep1.j rxml)



3 :我不知道明确需要 * .jasper 文件,不明白为什么我要处理它们。顺便说一句,JasperServer WebGUI似乎只支持上传 * .jrxml 文件)



JasperServer Web GUI



(例如,由某些Tomcat应用程序服务器提供并将其数据存储在某些postgres数据库中)



方案1:引用附加子报告资源




  • 如果您不想重复使用报告,将supreport添加到主报告中似乎很好(所以它在GUI repo树中是不可见的 - 参见下面的子项目,无论如何你可以在你的主人之外引用它。)

  • 如果你附上你的子报告,它通常应该有文件名作为其资源ID ,例如从上面我们的 subrep1.jrxml 上传资源ID subrep1.jrxml (从而处理本地设计引用和服务器引用不太复杂)

  • 从上面获取示例报告我们必须将 BASE_DIR 设置为 repo:在待上传的主报告中


    • 因此子报告表达式 $ P {BASE_DIR} +subrep1.jrxml $ P {BASE_DIR} +somesubdir / subrep2.jrxml应该有效在服务器上也是如此

    • 不推荐!:您仍然可以从其他报告中引用这些报告,其绝对路径如下 2 repo :/x/y/z/masterrep.jrxml_files/masterrep.jrxml _




2 :在这种情况下我不推荐;它没有记录,可能会更改;更好地将子报告放入GUI repo路径,如下所述)



场景2 :reference repo subreport resources(s)




  • 假设我们将子报告上传到主repo id-path / x / y / z / (如上图所示)


  • 我们必须再次区分两种不同的用途案例




    • 我们想要将子报告用作独立报告(它将始终只包含在其他主报告中)




      • 在这种情况下我们应该上传它使用 添加资源 - >文件 - > JRXML 并引用它


      • ../ subrep1.jrxml ./ subrep1.jrxml 不起作用,因为它似乎基础逻辑无法处理相对路径表达式 .. (和可能也)(这实际上很好:-()


      • 所以我们要做的就是提供一个绝对规范路径在masterrep.jrxml的 BASE_DIR 中,例如。 repo:/ x / y / z /



    • 我们希望将子报表用作独立报表以及




      • 在这种情况下,我们应该使用 添加资源 - > JasperReport


      • <上传p>这显然会创建一个隐藏文件夹 repo:/x/y/z/subrep1.jrxml_files 包含报告本身和其他资源


      • 这就是为什么我们不仅要调整 BASE_DIR (如上所述),还要将子报表表达式调整为,的例如 $ P {BASE_DIR} +subrep1.jrxml_files / subrep1.jrxml _ (指向子报告本身)



    • 可能会删除 net.sf.jasperreports.engine.JasperCompileManager.compileReport(...)包装函数,因为服务器会自动执行 * .jrxml files


    • 我没有完全调查一些其他可能错误使用的方法,这些方法对我来说无法解决上述问题(也许其他人在这里有一些结果/更正):




      • $ P {REPORT_FILE_RESOLVER} .resolveFile(subrep1.jrxml)(NullPointerException)

      • 导致主报告中的空子报表部分:


        • $ P {REPORT_CONTEXT} .getRealPath( subrep1.jrxml)

        • $ P {REPORT_CONTEXT} .getProperty(REPORT_FILE_RESOLVER)。resolveFile(subrep1.jrxml )






其他提示



因为我喜欢自动化报表设计和部署过程,所以我写了一些 ANT任务来处理本地* .jrxml文件可部署的* .jrxml文件转换有关 BASE_DIR 和其他转换。



SQL 有助于轻松调查 jasper服务器postgres元数据库中的资源ID路径结构(类似 jdbc:postgresql:// myjasperhost / jasperserver 连接例如与postgres用户):

 选择
f.id作为folder_id,
r.id作为res_id ,
f.hidden = true时的情况然后1其他0结束为隐藏,
f.uri ||情况当f.uri ='/'然后''else'/'end || coalesce( r.name,'')as res_uri,
r.resourcetype,
r.creation_date,
r.update_date,
f.uri,
r.name,
- 不太重要
r.version,
r.parent_folder,
r.childrenfolder,
f.parent_folder,
f.version,
f.name
- 从jiresourcefolder中选择*
f
左外连接jiresource r on(r.parent_folder = f.id)
其中不是f.uri like' / themes%'
由f.uri订购|| coalesce(r.name,'')



相关问题



与此相关的Jaspersoft论坛上的问题包括:




I searched for a couple of days to fix this bug with nothing new.

I had a report which include multi-level subreports everything works fine on iReport 3.7.5. I used subreport.jasper as subreport expression in the first level & also subreportA.jasper, subreportB.jasper in the second level & place all (the main report & subreports) in the same path.

The problem raised when I try to deploy it on my JasperServer. When I try to upload the first main report the iReport wizard offerd me to attach the first subreport.jrxml in resource folder and access it with repo:subreport.jrxml or repo:subreport.jasper. Then I manually upload the second level subreports and do the same thing change the subreport expression to repo:subreportA.jasper and repo:subreportB.jasper.

I got compilation error : Unable to locate the subreport with expression: ""repo:subreport.jasper"". java.lang.Exception: repo:subreport.jrxml not found.

I try dozen solution and nothing works. using : SUBREPORT_DIR @ the beginning,

using full path : repo:/Circuit_Reports/Connectivity/Connectivity_files/,

switch between .jasper & .jrxml.

using jasperserver_api_engine_impl_0_fix.jar in lib folder as a fixation to this bug,

I also searched the database record to be sure that they are in the same folder and have the same parent folder.

解决方案

Smalltalk before Longtalk ;)

(Of course I don't want to encourage you to read everything of this long detailed post! The bold markers may already be enough to solve your problems but I found it worth documenting this tricky stuff in some more detail!)

Since I invested another couple of hours on this (after I resolved it some weeks ago, had a change now, but forgot to document it properly, forgot how I did it and could not retrieve this info again in any form - when uploading and configuring to/in JasperServer) ... here is some aggregated functionality mentioned on various sites regarding subreport referencing, how it works and what one can try ...

(I'll update mine or other findings in here if there hopefully will be some)

Short cut details / best practices?!4

Till maybe Jasper functionality provides a similar "wrapping" solution itself ...

To workaround all the problems related to running the *.jrxml, *.jasper files either locally in Preview mode or remotely on a JasperServer I am now using the following approach which allows to work with only a single *.jrxml file, that will work locally and remotely without modifications, in a multi-developer environment, supporting independent refactoring of dir structures (paths, names) per environment (= as it should ;-) ):

  • using some jasper-utils-*.jar
    • put it in your project (Java) class path (Project->Properties->Java Build Path->Libraries->Add)
    • put it in your ../jasperserver/WEB-INF/lib/ folder
  • referencing some custom Jasper Java Scriptlet jr.utl.EnvScriptlet that does the ugly subreport path/reference magic in your master reports
    • define the REPORT_SCRIPTLET by adding an attribute to your master report: report properties -> Report -> Data Set -> Scriptlet Class: jr.utl.EnvScriptlet
  • using some custom properties file jr.utl.properties or otherwise supplied system properties (any other way to set the Java system properties would be fine as well and work - where already set up properties will override loaded file properties) to configure the different environments including your

    • current environment information via jr.utl.env property (prod, myOsUsrName, test, demo, staging, local, ...)
      • which determines how the subreport references must be generated / look like
    • server subreport parent directory property references
    • take e.g. these property file contents and put one per environment here:
    • on your servers: ../jasperserver/WEB-INF/classes/jr.utl.properties

      jr.utl.env=prod
      mycompany.local.jr.gui.rep.subrep1.parentdir=repo:/x/y/z/
      mycompany.local.jr.gui.rep.subrep2.parentdir=repo:/x/y/z/
      mycompany.local.jr.gui.rep.subrep3.parentdir=repo:/x/y/foobar/
      

    • in your local JasperSoft Studio (Eclipse) Java src/build path: e.g. ../myrepproject/src/java/jr.utl.properties

      jr.utl.env=dietrian
      mycompany.local.jr.gui.rep.subrep1.parentdir=D:/reporting/src/reports/
      mycompany.local.jr.gui.rep.subrep2.parentdir=D:/reporting/src/reports/
      mycompany.local.jr.gui.rep.subrep3.parentdir=D:/reporting/src/reports.otherdir/
      

      • to achive source modification independency in our environments we parameterized those values and generate them once via some workspace-dependent/user-specific local.properties file, based on this idea:

        |- build.xml                  (containing the ANT build magic)      
        |- build.properties           (containing global properties)      
        |- local.properties           (ignored in version control, e.g. .hgignore, user-specific generated from local.template.properties)
        |- local.template.properties  (source for ANT build task generating the local.properties above)
           |- mycomp.local.proj.reporting.dir=D:/reporting
        |- src/reports
           |- jr.utl.properties           (ignored in version control, user-specificly generated based on template below)
           |- jr.utl.template.properties  (source for ANT build task generating the jr.utl.properties above)
              jr.utl.env=${user.name}
              mycompany.local.jr.gui.rep.subrep1.parentdir=${mycomp.local.proj.reporting.dir}/src/reports/
              mycompany.local.jr.gui.rep.subrep2.parentdir=${mycompany.local.jr.gui.rep.subrep1.parentdir}
              mycompany.local.jr.gui.rep.subrep3.parentdir=${mycomp.local.proj.reporting.dir}/src/reports.otherdir/
        

  • defining your BASE_DIR master report parameters as e.g. $P{REPORT_SCRIPTLET}.getProp("mycompany.allsubreports.parentdir") (matching some environment-dependent property in your jr.utl.properties file)

  • defining the master subreport expressions as e.g. jr.utl.EnvScriptlet.getSubrepPath( $P{BASE_DIR}, "subrep1.jrxml")
    • automatically resolving the values from properties you could also use e.g. these variants:
      • jr.utl.EnvScriptlet.getSubrepPathByPropKey( $P{BASE_DIR}, "mycompany.local.jr.gui.rep.subrep1.name")
      • jr.utl.EnvScriptlet.getSubrepPathByPropKeys( "mycompany.local.jr.gui.rep.subrep1.parentdir", "mycompany.local.jr.gui.rep.subrep1.name")
    • $P{REPORT_SCRIPTLET}.getSubrepPath(...) does not work here :-( (I don't know why)
  • do not forget to restart your server when you put all the files on the server!

(4: Of course I am still seeing some minor improvements here, but it seems much better than all the ugly solutions I found till now. Improvements I would see:

  • using the REPORT_SCRIPTLET or scriptlet functionality may not be the best way to go, but it will probably work in the vast majority of use cases
  • although both existing Jasper classes suggest this they do not seem to be able to handle the above properly:

(5: the relevant special handling is encoded here: EnvScriptlet.java/getSubrepPath(String,String,boolean,String[]))

Intro (Background)

First thing to know is that the handling/setup in JasperStudio is quite different from the handling on Jasper Server (Repository)5 ...

suppose we have the following enviroments:

  • our Eclipse install dir: C:\eclipse\
  • our Eclipse (Report) workspace: C:\workspace\
  • our report project under: C:\workspace\report-project\
  • our reports under: C:\workspace\report-project\src/reports
  • a master report C:\workspace\report-project\src/reports/masterrep.jrxml
  • some subreport C:\workspace\report-project\src/reports/subrep1.jrxml
  • another subreport C:\workspace\report-project\src/reports/somesubdir/subrep2.jrxml
  • the BASE_DIR (explained in next section) in our workspace master report is set to C:\workspace\report-project\src/reports/
  • our Jasper Report Server GUI repo id-path of our master report will be: /x/y/z/ (which is not to-be-confused with the visual named-path, e.g. which could be Financial Reports/Expenses/Current Year)

In general: Jasper Studio, JasperServer

(and other "Jasper runtime environments" like custom Java Jasper package usage):

  • it seems a good practice to declare a report parameter "prefix" which can vary depending on your Jasper runtime environment e.g. named BASE_DIR
    • important here is that it seems best to assume the suffixed / may be included1 because there are cases where you may have/want to use it in a way where it should be an empty or "unslashed" path expression
      • e.g. $P{BASE_DIR} + "subrep1.jrxml" which should resolve to repo:subrep1.jrxml
    • see e.g. here for more details (look for SUBREPORT_DIR)

(1: which I personally find a bad practice in general (not looking at Jasper Reports in this respect) when dealing with directory-like structures)

JasperStudio Designer (Eclipse Plugin)

(the official IReport successor with loads of more functionality)

(if you do not use the preview functionality this may be uninteresting to you)

  • unfortunately I found no practical way to fully support (normal) "team-development" with subreports (and likely other relative resources as well), meaning here the (currently to me unknown) inexistent possiblity to separate local paths and *.jrxml files :-(
    • e.g. if you have a version control system in place and work in different environments (different local paths to repos and/or different developers) the master report has to contain a local path to your subreport in some way)
      • I tried different approaches that failed:
      • relative path expressions in BASE_DIR do not work since the working directory is the eclipse dir, e.g. C:\eclipse
      • Eclipse->Window->Preferences->JasperStudio->Properties->Add e.g. my.base.dir
        • it is not available in the Preview mode, e.g. via new java.io.File(System.getProperty("my.base.dir")).getCanonicalPath() + "/" for our BASE_DIR expression (these props may be only used by the designer itself, but not set in preview runs)
      • just in case you may stumble upon (as I did): Eclipse->Window->Preferences->JasperStudio->Report Execution->Virtualizer Temporary Path is something unrelated (not useful here) dealing with the storage of the report result "caching"
      • of course I could write an ANT task to replace these local pattern based on a regexp filter copy on every usage/checkout, but that seems not a good way to handle this
  • if you solely want to work with *.jrxml files (as I do3) you have to reference some subrep1.jrxml like this: net.sf.jasperreports.engine.JasperCompileManager.compileReport($P{BASE_DIR} + "subrep1.jrxml")

(3: I don't need the *.jasper files explicitely and do not see why I want to deal with them. BTW the JasperServer WebGUI only seems to support the upload of *.jrxml files)

JasperServer Web GUI

(e.g. provided by some Tomcat application server and storing its data in some postgres database)

Scenario 1: reference attached subreport resource(s)

  • if you do not want to reuse your report in general, it seems fine to add your supreport to your master report (so it is not visible in the GUI repo tree - see below subitem how you could reference it outside of your master anyways)
  • if you attach your subreport it should in general have its file name as its resource id, e.g. our subrep1.jrxml from above is uploaded with a resource id of subrep1.jrxml (thus making the handling of local design references and server references less complicated)
  • taking the example reports from above we have to set our BASE_DIR to repo: in the to-be-uploaded master report
    • thus the subreport expressions $P{BASE_DIR} + "subrep1.jrxml" and $P{BASE_DIR} + "somesubdir/subrep2.jrxml" should work on the server as well
    • NOT recommended!: you could still reference these reports from other reports with absolute paths like this2: repo:/x/y/z/masterrep.jrxml_files/masterrep.jrxml_

(2: which I would not recommend in this case; it's undocumented and may change; better put your subreports then into the "GUI repo path" as described below)

Scenario 2: reference repo subreport resource(s)

  • suppose we upload our subreports to the master repo id-path /x/y/z/ (as shown on top)

  • again we have to differentiate two different use cases

    • we do NOT want to use the subreport as a standalone report (it will always only be included in other master reports)

      • in this case we should upload it using Add Resource->File->JRXML and reference it

      • ../subrep1.jrxml or ./subrep1.jrxml do not work since it seems the underlying logic cannot handle the relative path expression .. (and likely . not as well) (which would actually be nice :-( )

      • so what we have to do here is to supply an absolute canonical path in the BASE_DIR of our masterrep.jrxml, e.g. repo:/x/y/z/

    • we want to use the subreport as a standalone report as well

      • in this case we should upload it using Add Resource->JasperReport

      • this obviously creates a hidden folder repo:/x/y/z/subrep1.jrxml_files containing the report itself and other resources

      • that's why we not only have to adjust the BASE_DIR (as above), but also the subreport expression to, e.g. $P{BASE_DIR} + "subrep1.jrxml_files/subrep1.jrxml_" (which points to the subreport itself)

    • and maybe remove the net.sf.jasperreports.engine.JasperCompileManager.compileReport(...) wrapper function, because the server does this automatically for *.jrxml files

    • I did not fully investigate some other likely incorrectly used approaches which did not work for me to solve the mentioned problems (maybe somebody else has some outcome/corrections here):

      • $P{REPORT_FILE_RESOLVER}.resolveFile("subrep1.jrxml") (NullPointerException)
      • resulting in empty subreport sections in master report:
        • $P{REPORT_CONTEXT}.getRealPath("subrep1.jrxml")
        • $P{REPORT_CONTEXT}.getProperty("REPORT_FILE_RESOLVER").resolveFile("subrep1.jrxml")

Additional hints

Since I like to automate the report design and deployment process as much as it makes sense I wrote some ANT tasks that handle the local *.jrxml file to deployable *.jrxml file transformations regarding the BASE_DIR and the other transformations.

SQL helpful to easily investigate the resource id path structures in a jasper server postgres meta database (following something like jdbc:postgresql://myjasperhost/jasperserver connecting e.g. with the postgres user):

select
    f.id as folder_id,
    r.id as res_id,
    case when f.hidden = true then 1 else 0 end as hidden,
    f.uri||case when f.uri = '/' then '' else '/' end||coalesce(r.name,'') as res_uri,
    r.resourcetype,
    r.creation_date,
    r.update_date,
    f.uri,
    r.name,
    -- less important
    r.version,
    r.parent_folder,
    r.childrenfolder,
    f.parent_folder,
    f.version,
    f.name
-- select *
from jiresourcefolder f
    left outer join jiresource r on (r.parent_folder = f.id)
where not f.uri like '/themes%'
order by f.uri||coalesce(r.name,'')

Related Questions

Questions on the Jaspersoft forum related to this one include:

这篇关于JasperServer:无法找到子报告异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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