Review
We have just completed our application! In the previous sections, we have discussed the functional specs, created the Java classes, designed the Jasper reporty layout, declared the configuration files, and wrote the JSP files. In this section, we will build and run the application using Maven, and show how to import the project in Eclipse.Table of Contents
Part 1: Introduction and Functional SpecsPart 2: Java classes
Part 3: Jasper layout with iReport
Part 4: HTML and jqGrid
Part 5: XML configuration
Part 6: Running the Application
Running the Application
Access the source code
To download the source code, please visit the project's Github repository (click here)Preparing the data source
- Run MySQL (install one if you don't have one yet)
- Create a new database:
spring_jasper_tutorial
- Import the following file which is included in the source code under the src/main/resources folder:
spring_jasper_tutorial.sql
Building with Maven
- Ensure Maven is installed
- Open a command window (Windows) or a terminal (Linux/Mac)
- Run the following command:
mvn tomcat:run
- You should see the following output:
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'tomcat'. [INFO] artifact org.codehaus.mojo:tomcat-maven-plugin: checking for updates from central [INFO] artifact org.codehaus.mojo:tomcat-maven-plugin: checking for updates from snapshots [INFO] ------------------------------------------ [INFO] Building spring-jasper-tutorial Maven Webapp [INFO] task-segment: [tomcat:run] [INFO] ------------------------------------------ [INFO] Preparing tomcat:run [INFO] [apt:process {execution: default}] [INFO] [resources:resources {execution: default-resources}] [INFO] [tomcat:run {execution: default-cli}] [INFO] Running war on http://localhost:8080/spring-jasper-tutorial Jan 31, 2012 10:39:22 PM org.apache.catalina.startup.Embedded start INFO: Starting tomcat server Jan 31, 2012 10:39:23 PM org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.29 Jan 31, 2012 10:39:23 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext Jan 31, 2012 10:39:29 PM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080
Note: If the project will not build due to missing repositories, please enable the repositories section in the pom.xml!
Access the Entry page
- Follow the steps with Building with Maven
- Open a browser
- Enter the following URL (8080 is the default port for Tomcat):
http://localhost:8080/spring-jasper-tutorial/
Import the project in Eclipse
- Ensure Maven is installed
- Open a command window (Windows) or a terminal (Linux/Mac)
- Run the following command:
mvn eclipse:eclipse -Dwtpversion=2.0
- You should see the following output:
[INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] org.apache.maven.plugins: checking for updates from central [INFO] org.apache.maven.plugins: checking for updates from snapshots [INFO] org.codehaus.mojo: checking for updates from central [INFO] org.codehaus.mojo: checking for updates from snapshots [INFO] artifact org.apache.maven.plugins:maven-eclipse-plugin: checking for updates from central [INFO] artifact org.apache.maven.plugins:maven-eclipse-plugin: checking for updates from snapshots [INFO] ----------------------------------------- [INFO] Building spring-jasper-tutorial Maven Webapp [INFO] task-segment: [eclipse:eclipse] [INFO] ----------------------------------------- [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse {execution: default-cli}] [INFO] Adding support for WTP version 2.0. [INFO] ----------------------------------------- [INFO] BUILD SUCCESSFUL [INFO] -----------------------------------------
This command will add the following files to your project:
.classpath .project .settings target
You may have to enable "show hidden files" in your file explorer to view them
- Open Eclipse and import the project
Conclusion
That's it! We've have successfully completed our Spring MVC 3.1 web application. We've learned how to add downloadable reports with JasperReports in an AJAX application, and use iReport to design the layout.I hope you've enjoyed this tutorial. Don't forget to check my other tutorials at the Tutorials section.
Revision History
Revision | Date | Description |
---|---|---|
1 | Jan 31 2012 | Uploaded tutorial and Github repository |
Share the joy:
|
Subscribe by reader Subscribe by email Share
You write great Spring tutorials. Keep up the good work!
ReplyDeletewhen run:
ReplyDeletemvn tomcat:run
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePl
uginFields(DefaultMavenPluginManager.java:613)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfigu
redMojo(DefaultMavenPluginManager.java:529)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:92)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:209)
... 23 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/beans/factory/Ini
tializingBean
no more error. Because of local repository conflict. It is OK after remove all old repository.
ReplyDeleteThank you for your spring tutorial.
ReplyDeletebut i can't deploy the application
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'e
ntityManagerFactory' defined in ServletContext resource [/WEB-INF/spring-data.xml]: Invocation of in
it method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.Persistence
UnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
@thread, how do you deploy your application via Maven? What application server are you using?
ReplyDeleteYou have made a great job. Thx a lot.
ReplyDeleteGreat tutorials! Thank you! :D
ReplyDeleteThank you very much for sharing your knowledge !!!
ReplyDeletejava.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRPropertiesUtil, at
ReplyDeletehttp://localhost:8080/users/download?token=d534c184-73a3-4ea5-8a1e-3091583a7a59&type=pdf
Same error for me ...please help me....
Deletewhere can I download the source code?
ReplyDeleteInternet Business Ideas for 2020
ReplyDelete