如何只编译.jrxml一次 [英] How to compile .jrxml only once

查看:158
本文介绍了如何只编译.jrxml一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助:
.jrxml每次生成报告时都在编译。我只想编译一次。请帮助我,我需要添加什么条件。我没有使用输入/输出流。使用compileReport只能编译一次。

Please Help: .jrxml is compiling every time i generate the report. I want to compile it only once. please help me what condition should i need to add. i am not using input/output stream. with compileReport what can be done to compile only once.

推荐答案

不要在任何可通过Web访问的地方提供JRXML文件。 JRXML文件包含易于读取的SQL语句,它们可以放弃:

Don't make your JRXML file available anywhere that is web accessible. The JRXML file contains easily read SQL statements, which give away:


  • 数据库供应商

  • 数据库结构

恶意用户可以将此信息用于恶意目的。我倾向于将SQL语句移动到数据库视图或存储过程中,这会隐藏很多信息。

Malicious users can use this information for nefarious purposes. I tend to move the SQL statements into database views or stored procedures, which hides much information.

您的报告创建过程应如下所示:

Your reports creation process should be as follows:


  1. 与业务分析师交谈以确定所有报告的报告要求。

  2. 合并所有简单变化的报告(例如,不同列或排序顺序)。

  3. 为每个报告创建JRXML文件(一个JRXML文件可以处理多个报告变体),将JRXML文件存储在源代码存储库中。

  4. 编译JRXML文件以获取 .jasper 文件。

  5. 存储已编译的 .jasper 存储库和Web服务器上的文件。

  6. 完全从源代码中删除编译步骤。

  1. Talk with a Business Analyst to determine report requirements for all reports.
  2. Amalgamate all reports that are simple variations (e.g., different column or sort order).
  3. Create JRXML files for each report (one JRXML file can handle several report variations), store the JRXML file in a source code repository.
  4. Compile the JRXML files to get .jasper files.
  5. Store the compiled .jasper files in the repository and on the web server.
  6. Remove the compilation step from your source code altogether.

简而言之,编译报告是一个应该在应用程序环境之外进行的过程。这是开发人员应该采取的步骤。开发人员将已编译的报告检入存储库,测试/构建环境可以获取最新的副本。

In short, compiling the report is a process that you should do outside of the application environment. This is a step that the developer should take. The developer checks the compiled report into the repository and the test/build environment can fetch the latest copy.

除非您有绝对的要求即时编译报告。请注意,除非您要创建动态报告,否则即时编译报告并不合理。在这种情况下,您需要使用 DynamicJasper 之类的内容。

Unless you have an absolute requirement to compile reports on-the-fly. Note that compiling reports on-the-fly does not really make sense unless you are creating dynamic reports. In that case, you'd want to use something like DynamicJasper.

所有这一切,你的问题的答案是:

All that said, the answer to your question is this:


  1. 尝试获取 Sample_Report的来源.jasper

  2. 如果 Sample_Report.jasper 资源不存在,那么就像你一样编译显示。

  3. 如果资源确实存在,请避免编译步骤。

  1. Try to obtain the source for Sample_Report.jasper.
  2. If the Sample_Report.jasper resource does not exist, then compile as you've shown.
  3. If the resource does exist, avoid the compilation step.

这可能类似于:

JasperReport jasReport = null;

try {
  jasReport = (JasperReport)JRLoader.loadObject(
    getResourceAsStream("Sample_Report.jasper")
  );
}
catch( Exception e ) {
  jasperReport = JasperCompileManager.compileReport(
    getResourceAsStream("Sample_Report.jrxml")
  );
}

你必须确保正确的目录,如果他们可以加载文件事实上,确实存在于这些地方。您还必须在编译后保存已编译的报告,以便下一次迭代将获取 .jasper 文件。

You will have to ensure the correct directories and the files can be loaded if they do, in fact, exist in those locations. You will also have to save the compiled report after it has been compiled, so that the next iteration will pick up the .jasper file.

要保存已编译的 .jasper 文件,可以使用以下 API

To save the compiled .jasper file, you can use the following API:

JasperCompileManager.compileReportToStrem(input, output);

参见:

  • http://community.jaspersoft.com/questions/527132/how-load-jasper-instead-jrxml
  • http://community.jaspersoft.com/questions/538416/how-save-compiled-jasper-object-database-blob

这篇关于如何只编译.jrxml一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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