Review
We have just completed our application! In the previous sections, we have discussed the functional specs, created the Java classes, declared the configuration files, and wrote the HTML 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: SendGrid account setup
Part 3: Java classes
Part 4: XML configuration
Part 5: Running the Application
Running the Application
Access the source code
To download the source code, please visit the project's Github repository (click here)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-sendgrid-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-sendgrid-tutorial Jun 18, 2012 10:27:47 PM org.apache.catalina.startup.Embedded start INFO: Starting tomcat server Jun 18, 2012 10:27:47 PM org.apache.catalina.core.StandardEngine start INFO: Starting Servlet Engine: Apache Tomcat/6.0.29 Jun 18, 2012 10:27:48 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext Jun 18, 2012 10:27:49 PM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 Jun 18, 2012 10:27:49 PM org.apache.coyote.http11.Http11Protocol start INFO: Starting 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-sendgrid-tutorial/email
Send an email
- Compose and email
- Send it. You should see within the logs an output similar to the following:
[DEBUG] [tomcat-http--23 04:25:03] (TraceInterceptor.java:writeToLog:21) Entering EmailController.send(org.krams.domain.Message@486d1d) [DEBUG] [tomcat-http--23 04:25:03] (TraceInterceptor.java:writeToLog:21) Entering SendGridEmailService.send(org.krams.domain.Message@486d1d) [DEBUG] [tomcat-http--23 04:25:04] (TraceInterceptor.java:writeToLog:21) Leaving SendGridEmailService.send(): StatusResponse [success=true, message=Message sent, ] [DEBUG] [tomcat-http--23 04:25:04] (TraceInterceptor.java:writeToLog:21) Leaving EmailController.send(): StatusResponse [success=true, message=Message sent, ]
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-sendgrid-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 email application with Spring and SendGrid integration. We've learned how to setup a SendGrid account and how to utilize its Web API via Spring's RestTemplate.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 | June 18 2012 | Uploaded tutorial |
Share the joy:
|
Subscribe by reader Subscribe by email Share
Thanks for sharing your knowledge.
ReplyDeleteHow to send attachments?
Check the following tutorial on how to do file uploads with Spring http://krams915.blogspot.com/2012/06/file-upload-with-spring-and-jquery-part_2793.html
DeleteRegarding on how to send attachments, that will be my next tutorial for this week. I just had to release first the email and the file upload tutorials first. For those who just prefer plain email and plain file uploads. The next tutorial will be a blending of both.
can you tell what is user and key. is it login user and password or sendGrid key. I am using my login id and password but message is not sending.
ReplyDeleteWhere is the source code ? Please do provide it.
ReplyDeleteThanks,
Savani
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
ReplyDeletedigital marketing company in nagercoil
digital marketing services in nagercoil
digital marketing agency in nagercoil
best marketing services in nagercoil
SEO company in nagercoil
SEO services in nagercoil
social media marketing in nagercoil
social media company in nagercoil
PPC services in nagercoil
digital marketing company in velachery
digital marketing company in velachery
digital marketing services in velachery
digital marketing agency in velachery
SEO company in velachery
SEO services in velachery
social media marketing in velachery
social media company in velachery
PPC services in velachery
online advertisement services in velachery
online advertisement services in nagercoil
web design company in nagercoil
web development company in nagercoil
website design company in nagercoil
website development company in nagercoil
web designing company in nagercoil
website designing company in nagercoil
best web design company in nagercoil
web design company in velachery
web development company in velachery
website design company in velachery
website development company in velachery
web designing company in velachery
website designing company in velachery
best web design company in velachery
Thanks for Sharing - ( Groarz branding solutions )
sivas
ReplyDeletebilecik
denizli
erzincan
uşak
PGTR