In this tutorial, I will guide you all how to create a new web application support Maven in Eclipse.
First, in Eclipse, go to File, select New and select Maven project:
To create a web project with Maven, we will use Maven Archetype with Archetype for the web application. Maven Archetype is a Maven feature that allows us to quickly create a Maven project with the structure of a predefined project. We only need to change the values such as Group Id, Artifact Id or Version to the value which we want.
In the window above, we will not choose Create a simple project (skip archetype selection), leave it by default and then click Next button.
This is the window that allows us to choose Maven Archetype. Maven Archetype for web application is named maven-archetype-webapp, then you should choose it:
then click Next button:
This is the window that allows us to change the values of Maven Group Id, Maven Artifact Id, Version and also the package name.
I will fill these values as follows:
Click Finish to complete.
As you can see, our project is reporting an error.
The reason is that: by default, Maven Archetype does not declare the Java Servlet dependency so we need to do this. You need open the pom.xml file and then add the dependency of the Java Servlet as follows:
Here, we can use Maven Jetty Plugin to run our application.