Step by Step guide – Convert to Maven Project in Eclipse
This post is for step by step guide to convert a single project to Maven project in Eclipse. I recommend going through these links before you read any further.
- Step by Step guide to configure Eclipse and Apache Tomcat
- Step by Step guide for Hello World Page (HTML and Jsp)
Step 1: Maven Plugin for Eclipse
First you should make sure that you have Maven Plugin installed in your Eclipse. I am using Eclipse Mars for this demo and this version comes with Maven Plugin. If you are using Eclipse doesn’t have this built in feature then try to install a Maven Plugin. I recommend M2Eclipse Plugin.
Step 2: Convert Java/J2ee Project to Maven Project
Right click on Java Eclipse and select Configure -> Convert to Maven Project.
A popup up that will show build parameters that will be published in pom.xml will be shown.
Step 3: Add dependencies to pom.xml
Open pom.xml and Click on Dependencies tab.
Lets try to add log4j.jar as a dependency in pom.xml.
Step 4: Run Maven Build
Run Maven build by right clicking on pom.xml and selecting Run As -> Maven install.
Step 5: Verify Build
You will see that folder is created with naming convention <artifactId>-<version> in build folder. Also you will see that all dependencies are saved to build/<artifactId>-<version>/WEB-INF/lib folder. Also you will see all dependecies are placed in build path under Maven Dependencies.
Multiple dependencies can be added in similar fashion.