Get A Running Web App in 5 minutes using Maven.

Below I will provide the steps to create a web-app using maven and get it running on tomcat, in just 5 minutes and without downloading and setting anything explicitly.

What you need is :
1. jdk 1.5 and above
2. maven 3
3. Eclipse or any IDE

Maven Archetype
We would be using maven archetype to create initial setup of our project.

1. Navigate to the folder where you want to create your app and run this command.

mvn archetype:generate -DgroupId=com.anirudh.myLearningPortal -DartifactId=myLearningPortal -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

2. Now go to the newly created project folder : cd myLearningPortal
3. Here you will see the complete directory structure and a POM.xml
4. To import this projecct to eclipse, run the following command :

mvn eclipse:eclipse

5. Import this project in eclipse as an existing project.
6. Now run mvn clean install to make sure everything is fine and the project is setup correctly.
7. After build is successful. Lets add tomcat plugin and maven compiler plugin in POM.xml so that we dont need to setup tomcat or do any manual build and deploy.


8.Finally run mvn clean install on the project folder.
9. If build is successful, run the below command:
mvn tomcat:run -Dmaven.tomcat.port=7080

10.When the server has started hit http://localhost:7080/myLearningPortal.
You will see “Hello World”, you can modify index.jsp to change the message.

So, now you have the running web-app, Now you can add any dependencies of spring,hibernate you wish to add in your application in POM.xml.
And compile,build and deploy your app in 2 commands.

1.Continous delivery, early feedback.
2.Any changes to view/jsp, no need to restart/compile ,it will reflect changes on page refresh.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.