- Install iReport 3.6.0
- Do a report with it and let it compile the report and it's subreports for you.
- Fetch jasperreports-project 3.6.0 and uncompress it
- Run ant jar at the root of uncompressed directory
- Copy every jar-file from both dist- and lib-subdirectories to /var/lib/tomcat5/shared/lib
- Make sure that tomcat can read copied files
- Copy your database jdbc class to same directory
- Restart tomcat
- Do a directory that tomcat can write and read from
- Copy your compiled jasper-reports (.jasper)-fiels to that directory
Here is an example that can produce pdf-report with subreports and parameters from Postgresql-database.
<?php
require_once('java/Java.inc');
// Get the database connection
$drv = new Java('org.postgresql.Driver');
$objDbm = java("java.sql.DriverManager");
$objDbConnect = $objDbm->getConnection("jdbc:postgresql://host/databasename", "user", "passwords");
// My report has one subreport and requires five parameters
// they are all STRINGS! I tried dates and timestamps but something chokes
$company='1105366-9';
$toimpiste='kaikki';
$startDay="2009-08-01"
$endDay="2009-09-01"
//
// This is the directory tomcat needs to be able to write and read from
// it contains the compiled reports (.jasper-files)
//
$reportPath="/web/Pikkusisko2/raporttimallit/";
// Parameters are passed in java hashmap, one way to generate one is
// like this
$parameters=new Java("java.util.HashMap");
$parameters->put('pYritys',$company);
$parameters->put('pToimipiste',$toimipiste);
$parameters->put('SUBREPORT_DIR',$reportPath);
$parameters->put('pAlkupaiva',$startday);
$parameters->put('pLoppupaiva',$endday);
// Generate report pdf
$jasperRunManager = new Java("net.sf.jasperreports.engine.JasperRunManager");
$rep=$jasperRunManager->runReportToPdfFile("$reportPath/projektit2.jasper", $parameters, $objDbConnect);
?>