Java Reporting Tools: a Comparison – Java报告工具:一个比较

最后修改: 2020年 8月 10日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

When we talk about Reporting tools, a lot of software covers this area. However, most of them are full-fledged Business Intelligence platforms or Cloud services.

当我们谈论报告工具时,很多软件都涵盖了这个领域。然而,它们中的大多数是成熟的商业智能平台云服务

But, what happens if we just want to add some reporting features to our application as a library? We will review here some Java reporting tools well suited for this purpose.

但是,如果我们只是想把一些报告功能作为一个库添加到我们的应用程序中,会发生什么?我们将在此回顾一些Java报告工具非常适合这一目的。

We will mainly focus on these open-source tools:

我们将主要关注这些开源工具。

In addition, we will briefly analyze the following commercial tools:

此外,我们将简要分析以下商业工具。

2. Designing Reports

2.设计报告

Through this section, we’ll review how we can visually design reports and play with our data. Note we’ll be referring only to open-source tools in this part.

通过这一部分,我们将回顾我们如何直观地设计报告和玩弄我们的数据。请注意,我们在这一部分只提到了开源工具。

2.1. Visual Editors

2.1.视觉编辑

All the three tools include a WYSIWIG editor with report previewing capabilities.

所有这三种工具都包括一个具有报告预览功能的WYSIWIG编辑器。

BIRT Report Designer and Jaspersoft Studio are tools built on Eclipse RCP. This is a good point for most of us Java developers, as we might be familiar with the Eclipse environment. Unlike those, Pentaho Report Designer has aged visually poorly.

BIRT Report DesignerJaspersoft Studio是建立在Eclipse RCP的工具。这对于我们大多数 Java 开发人员来说是一个很好的点,因为我们可能对 Eclipse 环境很熟悉。与这些不同,Pentaho Report Designer在视觉上的老化程度很差

Also, there is an additional interesting feature about Jaspersoft Studio: we can publish our reports directly on their Jasper Reports Server (the report management system).

此外,关于Jaspersoft Studio还有一个有趣的功能:我们可以直接在他们的Jasper Reports Server(报告管理系统)上发布我们的报告。

2.2. Datasets

2.2.数据集

As with all reporting tools, we can retrieve datasets by querying a datasource (see below). Then, we can transform them into report fields, create computed fields, or use aggregation formulas.

与所有报告工具一样,我们可以通过查询datasource来检索数据集(见下文)。然后,我们可以将它们转化为报告字段,创建计算字段,或使用聚合公式。

Besides this, it’s interesting to compare how we can manage multiple datasets as we may need several of them if our data comes from different queries or even different datasources:

除此之外,比较一下我们如何管理多个数据集也很有意思,因为如果我们的数据来自不同的查询,甚至不同的数据源,我们可能需要几个数据集。

  • BIRT offers the easiest solution as we can have multiple datasets in the same report
  • With Jasper Reports and Pentaho, we need to create a separated subreport each time, which can be quite tricky

2.3. Charts and Visual Elements

2.3.图表和视觉元素

All the tools provide simple elements like shapes and images, and also every chart flavor: lines, areas, pies, radar, ring, etc. All of them support cross-tabs too.

所有的工具都提供简单的元素,如形状和图像,也提供每一种图表的味道。line, areas, pies, radar, ring, 等等。所有这些也都支持交叉标签。

However, Jasper Reports provides the richest visual elements collection. It adds to the above list maps, sparklines, pyramids, and Gantt diagrams.

然而,Jasper Reports提供了最丰富的视觉元素集合。它在上述列表中增加了mapssparklinespyramidsGantt diagram

2.4. Styling Reports

2.4.造型报告

Now, let’s compare the positioning and sizing of elements in the page:

现在,让我们比较一下页面中元素的定位和大小。

  • All of the tools provide pixel-positioning
  • BIRT and Pentaho also provides HTML-like positioning (table, block, inline)
  • None of them supports CSS-like flexbox or grid system to control elements size

Also, when we have to manage multiple reports, we may want to share the same visual theme:

另外,当我们必须管理多个报告时,我们可能希望共享同一个视觉主题。

  • Jasper Reports provides theme files with XML-CSS syntax
  • BIRT can import CSS stylesheets into the design system
  • With Pentaho, we can only add CSS stylesheets in the page header. So it’s difficult to mix them with the internal design system

3. Rendering Reports

3.渲染报告

Now, that we’ve seen how to design reports, let’s compare how we can render them programmatically.

现在,我们已经看到了如何设计报告,让我们比较一下如何以编程方式呈现它们。

3.1. Installation

3.1.安装

First, let’s note that all the tools have been designed to be easily embedded within a Java project.

首先,让我们注意到,所有的工具都被设计成可以轻松嵌入到Java项目中

To get started, you can have a look at our dedicated articles about BIRT and Jasper Reports. For Pentaho, there’s a help page and free code samples.

要开始使用,你可以看看我们关于BIRTJasper Reports的专门文章。对于Pentaho,有一个帮助页面和免费的代码样本

Next, for each of these tools, we will connect the report engine to our application data.

接下来,对于这些工具中的每一个,我们将把报告引擎连接到我们的应用数据。

3.2. Datasource

3.2.数据来源

The first question we should ask is: how can we connect the report engine to our project datasource?

我们应该问的第一个问题是:我们如何将报告引擎连接到我们的项目数据源?

  • Jasper Reports: we simply add it as a parameter of the fillReport method
  • BIRT solution for this is a bit more complex: we should modify our report to set the datasource attributes as parameters
  • Pentaho has a big drawback here: unless we buy their PDI commercial software, we have to use a JNDI datasource, which is more difficult to set up

Speaking of datasources, which types are supported?

说到数据源,支持哪些类型?

  • All three tools support the most common types: JDBC, JNDI, POJOs, CSV, XML and MongoDB
  • REST API is a requirement for modern projects, however, none of them support it natively
    • with BIRT, we should code a Groovy script
    • Jasper Reports requires an extra free plugin
    • with Pentaho, we should code a Groovy script or acquire the PDI commercial software
  • JSON files are supported natively by Jasper Reports and Pentaho, but BIRT will require an external Java parser library
  • We can find the complete comparison list in this matrix

3.3. Parameters and Runtime Customization

3.3.参数和运行时定制

As we have connected our report to our datasource, let’s render some data!

由于我们已经将我们的报告连接到了我们的数据源,让我们来渲染一些数据吧!

The important thing now is how to retrieve our end-user data. To do this, we can pass parameters to the rendering method. These parameters should have been defined when we designed the report, not at runtime. But what can we do if, for example, our dataset is based on different queries depending on the end-user context?

现在重要的是如何检索我们的终端用户数据。要做到这一点,我们可以向渲染方法传递参数。这些参数应该在我们设计报告的时候就已经定义好了,而不是在运行时。但是,如果,比如说,我们的数据集是基于不同的查询,取决于终端用户的上下文,我们能做什么呢?

With Pentaho and Jasper Reports, it is simply not possible to do that, as the report file is binary and there is no Java SDK to modify them. By comparison, BIRT reports are plain-XML files. Moreover, we can use a Java API to modify them, so it’s very easy to customize everything at runtime.

对于PentahoJasper Reports,根本不可能做到这一点,因为报告文件是二进制的,没有Java SDK来修改它们。相比之下,BIRT报告是纯XML文件。此外,我们可以使用Java API来修改它们,所以在运行时很容易定制一切。

3.4. Output Formats and Javascript Clients

3.4.输出格式和Javascript客户端

Thankfully, most of the common formats are supported by all the tools: HTML, PDF, Excel, CSV, plain text, and RTF. Nowadays, we may also ask how we can integrate the report result directly into our web pages. We will not mention the rough inclusion of a PDF visualizer though.

值得庆幸的是,大多数常见的格式都被所有的工具所支持。HTML、PDF、Excel、CSV、纯文本、RTF。现在,我们也可能会问,如何才能将报告结果直接整合到我们的网页中。虽然我们不会提到粗略地包含一个PDF的可视化工具。

  • The best solution is to use Javascript clients to render reports directly into an HTML element. For BIRT, the Javascript client is Actuate JSAPI and for Jasper Reports, we should use JRIO.js
  • Pentaho does not provide anything but iFrame integration. This solution works but may have serious drawbacks

3.5. Standalone Rendering Tools

3.5.独立的渲染工具

Besides integrating our report into a web page, we may also be interested in having an out-of-the-box rendering server. Each tool provides its own solution:

除了将我们的报告整合到一个网页中,我们可能还对拥有一个开箱即用的渲染服务器感兴趣。每个工具都提供自己的解决方案。

  • BIRT Viewer is a lightweight web application sample to execute BIRT reports on-demand. It’s open-source but does not include report management features
  • for Pentaho and Jasper Report, there are only commercial software packages

4. Projects Status and Activity

4.项目状况和活动

First, a word about licenses. BIRT is under EPL, Jasper Reports under LGPLv3, and Pentaho under LGPLv2.1. Thus, we can embed all of these libraries into our own products, even if they are commercial.

首先,关于许可证的问题。BIRT属于EPLJasper Reports属于LGPLv3,而Pentaho属于LGPLv2.1。因此,我们可以将所有这些库嵌入我们自己的产品中,即使它们是商业产品。

Then, we can ask ourselves how these open source projects are maintained, and if the community is still active:

然后,我们可以问自己,这些开源项目是如何维护的,以及社区是否仍然活跃。

  • Jasper Reports has a well-maintained repository, with a stable medium activity by its editor TIBCO Software
  • BIRT repository remains maintained, but its activity is very low since 2015 when OpenText acquired its editor Actuate
  • Similarly, Pentaho repository activity is very low since Hitachi-Vantara acquisition in 2015

We can confirm this using Stackoverflow trends. The lowest popularity is for BIRT and Pentaho, but is moderate for Jasper Reports.

我们可以用Stackoverflow的趋势来证实这一点。流行度最低的是BIRTPentaho,但对于Jasper Reports来说是中等的。

All three Java reporting tools have decreased in popularity in the past 5 years although remain stable for now. We can explain this by the emergence of the Cloud and Javascript offers.

所有这三种Java报告工具在过去5年中的受欢迎程度都有所下降,尽管目前仍保持稳定。我们可以通过云计算和Javascript的出现来解释这一现象

5. Commercial Java Reporting Tools

5.商用Java报告工具

Besides the open-source solutions, there are also some commercial options available that are worth mentioning.

除了开源的解决方案,还有一些值得一提的商业选择。

5.1. Fine Report

5.1 罚款报告

Fine Report has been initially designed to be executed as a standalone server. Fortunately, we’re able to include it as part of our project if we want to use it. We have to manually copy all JARs and resources into our WAR, as described in their procedure.

Fine Report最初被设计为作为一个独立的服务器来执行。幸运的是,如果我们想使用它,我们能够把它作为我们项目的一部分。我们必须手动将所有JAR和资源复制到我们的WAR中,如他们的程序中所述。

After doing this, we can see the Decision-making Platform tool available as a URL in our project. From this URL, we can execute reports directly in the provided web view, an iFrame, or using their Javascript client. However, we can’t generate reports programmatically.

这样做之后,我们可以看到决策平台工具在我们的项目中作为一个URL可用。从这个URL中,我们可以直接在提供的Web视图、iFrame中执行报告,或者使用其Javascript客户端。然而,我们不能以编程方式生成报告。

Another huge limitation is the target runtime. Version 10 only supports Java 8 and Tomcat 8.x.

另一个巨大的限制是目标运行时间。版本10只支持Java 8和Tomcat 8.x。

5.2. Logi Report (formerly JReport)

5.2.Logi Report(以前的JReport)

Like Fine Report, Logi Report has been designed to be executed as a standalone server, but we can integrate it as part of our existing WAR project. Thus, we will face the same limitation as with Fine Report: we can’t generate reports programmatically.

与Fine Report一样,Logi Report被设计为作为独立的服务器来执行,但我们可以将其整合为我们现有WAR项目的一部分。因此,我们将面临与Fine Report一样的限制。我们不能以编程方式生成报告

Unlike Fine Report. however, Logi Report supports almost all servlet containers and  Java 8 to 13.

然而,与Fine Report不同,Logi Report支持几乎所有的servlet容器和Java 8至13。

5.3. ReportMill Reporting

5.3.ReportMill报告

Finally, ReportMill is worth mentioning because we can embed it smoothly into every Java application. Also, like BIRT, it’s very flexible: we can customize reports at runtime as they are plain XML files.

最后ReportMill值得一提,因为我们可以将它顺利地嵌入到每个Java应用程序中。此外,与BIRT一样,它也非常灵活。我们可以在运行时定制报告,因为它们是纯XML文件

However, we can see right away that ReportMill has aged, and also has a poor set of features comparing to the other solutions.

然而,我们马上就能看到,ReportMill已经老化,而且与其他解决方案相比,它的功能也很差。

6. Conclusion

6.结语

In this article, we went through some of the most well known Java reporting tools and compared their features.

在这篇文章中,我们经历了一些最知名的Java报告工具,并比较了它们的功能。

As a conclusion, we can pick one of these Java Reporting Tools depending on our requirements:

综上所述,我们可以根据自己的要求来选择这些Java报告工具中的一个。

We’ll choose BIRT:

我们将选择BIRT

  • For a simple library to replace an existing home-made solution
  • For its greatest flexibility and high customization potential

We’ll choose Jasper Reports:

我们将选择Jasper Reports

  • If we need a reporting library compatible with a full-fledged report management system
  • If we want to bet on the best long-term evolution and support