How to create a maven web application project in Eclipse

By | October 25, 2020

In this post, We will learn How to create a maven web application project in Eclipse

Follow the below steps to create a maven web application project in Eclipse:

1) Open the Eclipse and Go to File -> New -> Others.

2: In the opened New wizard, scroll down and select Maven->Maven Project, click Next

3: In the below screen, If you do not want to create your maven project on the default Workspace location then Uncheck the “Use default Workspace location” checkbox option and with the help of the Browse button choose your workspace where you would want to create your Maven project. Click on Next.

4: Just scroll down and select option with Artifact Id as maven-archetype-webapp and Click on Next

5: Now provide Group Id, Artifact Id & version. These attributes basically give your project deliverable(jar/war/ear etc.. ) a unique identity in the repository. Click Finish

5: Your project structure should like the below one.

Note: In case if you do not see the src/main/java and src/test/java directories in your project structure then you will have to go to Project ->Properties ->Java BuildPath ->Libraries after that select JRE System Library and click on Edit and Select or configure correct JRE System Library click on Finish and then click on Apply. You should see those( src/main/java and src/test/java) folders/directories now. You may also right-click on your project then maven -> Update Project->Ok to perform a maven-update on your project.

Note: You should keep in mind that in recent Eclipse versions you don’t need to use mvn eclise:eclipse anymore because this functionality is now built-in with the recent m2e eclipse plugin

6: Finally, You will have to update your pom.xml based on your project requirement (adding dependencies, profiles, plugins, repositories etc..)

Below pom.xml is by default generated by our Project:

The dependency section refers to the library on your project is relying upon. These libraries can be found on different maven repositories.

For instance, if your code is using Servlet API and your test cases rely upon JUnit Jupiter, your pom.xml will include the dependency for Servlet API and JUnit Jupiter like below:

That’s all about How to create a maven web application project in Eclipse
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *