|
Re: How can i integrate jasper reports on scout? [message #1758013 is a reply to message #1755991] |
Wed, 22 March 2017 18:25 |
Eclipse User |
|
|
|
Jasper integration:
The integration is basically the same as in any other java/maven environment (lots of tuturials around).
- pom dependencies
Add the following dependencies to your project. Usually in the server parts pom file.
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<!-- <version>1.0-2</version> -->
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
- Report definition
Create a report definition (*.jrxml) e.g. using the report designer and put it into the <your module>/src/main/resources/jasper.
- Create the report
Could look like:
InputStream billStream = getClass().getResourceAsStream("/jasper/bill.jrxml");
try {
JasperReport jasperBillReport = JasperCompileManager.compileReport(billStream);
Map<String, Object> parameters = new HashMap<>();
// put parameters here
JRBeanCollectionDataSource connection = new JRBeanCollectionDataSource(CollectionUtility.arrayList(yourBean));
JasperPrint print = JasperFillManager.fillReport(jasperBillReport, parameters, connection);
return JasperExportManager.exportReportToPdf(print);
}
catch (JRException e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e);
}
A sample implementation is available under Github Docbox.
-andreas
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02793 seconds