Spring Jasper Report with Maven. Example to convert web application to maven based in Eclipse.
This tutorial is a continuation of my old tutorial that is to generate dynamic reports from database using Jasper Reports in Spring 4 mvc. The example project (SpringJasperDemo) used in that tutorial was developed without maven support. Here we will see how to develop the same project with maven support. Instead of rewriting the same tutorial again, we will see here how to convert the same project into maven based. This can be done in two ways.
I) Option 1:
1. Check out the old project (SpringJasperDemo without maven) using github repository
https://github.com/vkjegan/SpringJasperDemo
1. You can convert the exisiting project by right clicking on the project and select Configure ->Convert to Maven Project
2. Fill the Artifact details like Group Id, Artifact Id, etc..
3. Click on Finish. Now the project is converted to maven based and the new project structure is given below.
Project Structure:
2. Replace the content of pom.xml file with the content of pom.xml given below.
For java code, XML template and steps, please visit my old tutorial
Now we will see the pom.xml to develop the same project using maven.
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.javaonline</groupId> <artifactId>spring.jasper</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>SpringJasperMaven Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>net.sf.jasperreports</groupId> <artifactId>jasperreports</artifactId> <version>6.0.0</version> </dependency> <dependency> <groupId>tomcat</groupId> <artifactId>jasper-compiler-jdt</artifactId> <version>5.5.23</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.3.1.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> <version>3.2.1.ga</version> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.0.0.GA</version> </dependency> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>SpringJasperMaven</finalName> </build> </project> |
II) Option 2:
1. Create a new maven based dynamic project by selecting File-> New->Other->Maven->Maven Project
2. Select Next
3. Select Workspace location where the project to be created and Next
4. Select an Archetype as webapp
5. Fill the details like GroupId, ArtifactId, etc.. and FInish
6. Copy the necessary source code, JSP, xml files from the old tutorial by creating necessary packages & folders
7. Replace the pom.xml file with the content of above pom.xml. If required add the below lines also in pom.xml for servlet api dependency.
1 2 3 4 5 |
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> |
8. Update the Maven Project by right clicking on the project and Select Maven->Update Project
9. Include Maven Dependencies in the Deployment Assembly by right clicking on the project and Select properties->Deployment Assembly
Add ->Java Build Path Entries -> Maven Dependencies and Finish & Ok.
Project Structure:
10. Compile and run the project by calling the URL
http://localhost:8080/<project Name>/loadJasper.do
Note: # This maven project is tested with Application Server Tomcat Apache 8
You can download the example project with source code at
For checking out the git repository, please visit my earlier post
How to share eclipse project to github and viceversa
Leave a Reply
You must be logged in to post a comment.