Pages

Tuesday, December 6, 2011

working with jasperreports.properties

jasperreports gives us numerous properties settings that we can customize at design or compile time and
modify/control the execution of reports.

Jasperreports has his own default settings and it reads it from its jar file jasperreports-x.x.x.jar with the file name default.jasperreports.properties, unless you specify differently. Property file gives us flexibility of changing its execution behavior at run time, it may get applied to all report or to specific report as well, all depend upon how you specify properties.
Following are the ways you can define the properties which will be read by jasper and work accordingly.

1. specify in system properties.
    if we want to load some specific properties then we can specify it system.setProperties(k,v) format and compiler will override it with default. used for global changes for all reports.
   
2. specify in jasperreports.properties file   
    create your own jasperreports.properties file (normally override default by copy and modify ) and place it in classpath so that compiler will override default properties. this will get applied to all reports getting compiled/executed so useful for global changes.
   
3. specify properties in template file.
    if you want to specify only for specific report and not for others there is way to specify properties at top of your report template so that those will be overridden by compiler with default properties. You can specify properties in template as below
   
   
there are few properties specifically for export can be set through exportmanager you use at time of exporting programmatically as exportmanager.setParameter(k,v) for example

property file has
net.sf.jasperreports.export.xls.one.page.per.sheet=false

same can be set at run-time programmatically in code using xlsExporter as below

xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);






hope this helps you.
Lastly, If possible before closing, click on ad to support me.