Monday, July 29, 2013

How to Create a Dynamic Web Project using Maven in Eclipse

Maven is very powerful instrument and if you know how to use it you will make minimum effort to achieve maximum result. In general Maven helps you to manage a project including library dependencies, building process and etc…
Here is a simple tutorial which you can go through to create Dynamic Web Project having Maven enabled inEclipse. This project can be used as base project and can be easily converted to most kind of advanced Java project like Spring MVC based etc.
Tools I’m using:
  • Eclipse
  • Maven
  • JSK 1.7
  • M2Eclipse Plugin
Step-1) Create a simple maven Project in Eclipse.



Step-2) Select the maven archetype as: maven-archetype-webapp and click on next.

2 Select maven archetype webapp How to Create Dynamic Web Project using Maven in Eclipse?


Step-3) Fill out below details.

3 Maven Specify ArcheType Parameters How to Create Dynamic Web Project using Maven in Eclipse?

Step-4) Click Finish.
Step-5) Your Maven Project should look like this.
4 Eclipse Maven Project Structure How to Create Dynamic Web Project using Maven in Eclipse?


Step-6) Now we have to convert Maven Webapp to Dynamic Web Project.
Step-7) Click on External Tool configuration And create a program name convert In main tab and providebelow parameters.
mavn parameters How to Create Dynamic Web Project using Maven in Eclipse?
Step-8) Click Run and your project build should show below SUCCESSFUL message.
9 Maven Successful How to Create Dynamic Web Project using Maven in Eclipse?

Step-9) Once the build is successful, you will have the Dynamic web application using maven. Make sure Project Facets should look like below diagram.

7 Eclipse Project Facets Variables How to Create Dynamic Web Project using Maven in Eclipse?


Step-10) Make Sure Maven Dependencies is added to your “Web Deployment Assembly”.

8 Maven Dependancies in Web Deploymnet Assembly How to Create Dynamic Web Project using Maven in Eclipse?


Step-11) Deploy Application on Tomcat.

Step-12) Visit http://localhost:8080/CrunchifyMavenExample/index.jsp

10 Run on Tomcat Maven Project Hello World How to Create Dynamic Web Project using Maven in Eclipse?

Step-13) And you are all set.
Do let me know if you find any exception creating this. I’ll try to fix for you.