3

I see there is a Scala wrapper for JasperReports, and I found a Clojure library for Scala interoperability, as well as a snippet of example code by a beginner from this discussion but I can't find any libraries or working example code for Jasper or DynamicJasper. I thought I had previously found a library or article. Any hints?

The problem is that the JasperReports API is incredibly messy (mutation-focused), so I don't want to write wrapper code from scratch.

sventechie
  • 1,859
  • 1
  • 22
  • 51

1 Answers1

1

This isn't a thorough tutorial but some pointers on how I've been using JasperReports with JRxml files and Clojure. I have no idea about DynamicJasper.

Here's some stuff you'll need to import.

(ns app.reports
  (:require [clojure.java.io :as io]
            [clojure.string :as s])
  (:import [net.sf.jasperreports.engine
            JasperCompileManager
            JasperFillManager
            JasperPrint
            JasperExportManager
            JREmptyDataSource
            JRExporter
            JRException]))

Compile your jrxml file:

(def my-report
  (JasperCompileManager/compileReport
    (io/input-stream
      (io/file "my-report.jrxml"))))

Use a Java HashMap with the data / columns you'll pass in to your report to fill it.

(def report-data
  (java.util.HashMap. {"attrname_1" "Attr 1 String"
                       "attrname_2" "More data..."}))

Fill your report with data from a source:

(def filled-report
  (JasperFillManager/fillReport my-report report-data (JREmptyDataSource.)

Export your report. Here's how to do it as a PDF.

(JasperExportManager/exportReportToPdfFile filled-report "result.pdf")

I hope this helps you get started.

sventechie
  • 1,859
  • 1
  • 22
  • 51
doritostains
  • 1,186
  • 10
  • 9
  • Thanks, I'll check that out! I started putting together a wrapper lib actually. You're most welcome to contribute or use it: https://github.com/sventechie/jasper-reports-clj – sventechie Nov 04 '15 at 21:09