gpt4 book ai didi

jasper-reports - JasperServer:无法定位子报表异常

转载 作者:行者123 更新时间:2023-12-04 04:30:01 42 4
gpt4 key购买 nike

我搜索了几天来修复这个错误,没有什么新东西。

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

当我尝试在我的 JasperServer 上部署它时出现的问题。
当我尝试上传第一个主报告时,iReport 向导让我将第一个 subreport.jrxml 附加到资源文件夹中,并使用 repo:subreport.jrxmlrepo:subreport.jasper 访问它。
然后我手动上传二级子报表并做同样的事情将子报表表达式更改为 repo:subreportA.jasperrepo:subreportB.jasper

我收到编译错误:Unable to locate the subreport with expression: ""repo:subreport.jasper"". java.lang.Exception: repo:subreport.jrxml not found.
我尝试了十几种解决方案,但没有任何效果。
使用:SUBREPORT_DIR@开头,

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

.jasper.jrxml 之间切换。

使用 lib 文件夹中的 jasperserver_api_engine_impl_0_fix.jar 作为此错误的修复,

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

最佳答案

在 Longtalk 之前的 Smalltalk ;)

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

由于我在这方面又投入了几个小时(几周前我解决了这个问题之后,现在进行了更改,但是忘记正确记录它,忘记了我是如何做的并且无法以任何形式再次检索此信息 - 在上传和配置时到/在 JasperServer 中)……这里有一些在各种站点上提到的关于子报告引用的聚合功能,它是如何工作的以及可以尝试什么……

(如果有希望的话,我会在这里更新我的或其他发现)

捷径细节/最佳实践?!4

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

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

  • 使用一些 jasper-utils-*.jar
  • 把它放在你的项目 (Java) 类路径 ( Project->Properties->Java Build Path->Libraries->Add )
  • 把它放在你的 ../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/build 路径 : 例如../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                  (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 torepo: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,'')

    相关问题

    Jaspersoft 论坛上与此相关的问题包括:
  • http://community.jaspersoft.com/questions/525466/proper-way-include-subreports
  • http://community.jaspersoft.com/questions/530526/subreport-could-not-load-object-location
  • http://community.jaspersoft.com/questions/517832/subreports-ireports
  • http://community.jaspersoft.com/questions/537611/sub-report-jrxml-jasper
  • http://community.jaspersoft.com/questions/534861/unable-compile-master-report-pls-advise
  • http://community.jaspersoft.com/questions/817852/databasetimezone
  • http://community.jaspersoft.com/questions/819343/comjaspersoftjasperserverapijsexception-error-filling-report-and
  • http://community.jaspersoft.com/questions/536251/solved-subreport-not-running-jasperserver
  • http://community.jaspersoft.com/questions/536218/resolved-problem-subreport-reference-after-exporting-ireport-jasperserver#81141
  • http://community.jaspersoft.com/questions/527109/subreport-problem
  • http://community.jaspersoft.com/questions/522331/atomatically-compile-subreports
  • 关于jasper-reports - JasperServer:无法定位子报表异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4364205/

    42 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com