iReport and Jasper Initial Impressions

Introduction

JasperServer and JasperReports are part of a comprehensive business intelligence reporting platform from JasperSoft. They bill it as "The Most Widely Used Open Source Business Intelligence" on their website (http://jaspersoft.com). Why, you might ask, would a web application developer be working on business intelligence reporting? There was a need at work to do some data mining, and since I have some previous BI experience several years ago working on a bank statement reporting project using one of Jasper's main competitors, Eclipse BIRT (Business Intelligence Reporting Tool) which is now maintained by Actuate (http://www.actuate.com/BIRT). I don't remember exactly what version of BIRT we were using at the time, but I do remember it not being all that mature, still with some bugs. Regardless, BIRT == iReport...they are pretty much the same tool. Looking at the BIRT website briefly makes me curious as to how much better it must be than when I used it. So that's the short of it. I'm going to proceed by telling you about the basics of the iReport tool for JasperReports and try to explain the most basic structure of a project.

First, it would make sense to put all this in context. What is the business problem? The specific problem that needed to be solved was the generation of website and other operational metrics on a monthly, quarterly and yearly basis for various clients. Sure, some of the website visitor information is available through standard web analytics tools such as Urchin - but this doesn't dig deep enough into our specific operations. Web reporting is typically rather extensive, but generic in nature. There are pieces of our system that need to be extracted from the Oracle database in a more custom manner with SQL. Additionally, we needed to output the reports in PDF format and possibly, down the road, in other richer formats for the web, etc. This is where JasperServer and iReports comes in. 

Where to Start?

One of the hardest things about starting to learn a new software tool is figuring out the best place to start. There are always tutorials, API docs, blog articles, etc...but which one is going to provide the best launching point to help maximize adoption of and learning about the new tool - while also minimizing ramp-up time. Luckily, folks at my company believe in support licenses and learning resources - so we had immediate access to the training materials such as "iReport Ultimate Guide", "JasperServer Ultimate Guide", etc. I would recommend purchasing these as they are good overall guides.

iReport

The first step of course is to get something installed on my computer so I can begin tinkering. JasperServer and iReport install pretty painlessly. To be honest though, in order to get started seeing the power of reporting, all you need to do is download and install the open source iReport software. iReport is a visual XML designer built on the NetBeans platform. You can get it here: http://jasperforge.org/projects/ireport - this is a standalone product that can not only help you design the reports (luckily, without having to touch too much XML!), but will connect to the database (or other datasources) and output your reports in various formats including XLS, PDF, etc.

SQL is a Must

For most applications of Jasper Reports, knowing SQL is a must. Since extracting data from a database is a primary goal of business intelligence reporting, you can understand why. My advice is - if you don't know SQL or you could use some brushing up, do it! The simplest form of report is a basic SQL query like:

SELECT first_name, last_name, insert_date
FROM db.users
WHERE insert_date > to_date('2009-10-01','yyyy-mm-dd')

Yep, that's about as basic as SQL can get and you know exactly what that result set is going to look like. So a query such as this is a good place to start in iReport.

Watch Out For Bugs!

Though the iReport tool is pretty nice (I'm currently using 3.5 pro) - it's not without its limitations and small bugs. I ran into a couple while working with it recently including XML tag properties that would mysteriously be changed to "null". The first time this happened I received a SAX parse error that pretty much told me that null was not a valid attribute. Great. Thanks. I didn't put it there. The problem with this error is that a corrupted XML file likely means that the designer view won't even show up, forcing you to go "caveman" and start modifying the XML by hand - in other words, go in and modify the property that was set to null. In my case the property was simply one that tells the text alignment for a container. Valid values are "Right", "Center" and "Left". I went in and changed these back to the value that I intended them to be. This worked, and the design view was now usable again, which was great - but having to do this every time I load a JRXML (the acronym given to the standard XML definition file for a Jasper report) file became quite tedious. This is an obvious bug, that in a more complex report layout, could end up being a real PITA, if you know what I'm saying.

In Part 2...

In part 2 I'll go into more specifics regarding generating your first report. I'll explain what .jrxml and .jasper files are, explain the basics of setting up your services and datasources, how to use the basic building blocks such as frames, text labels, bands, etc.