Create web application using Maven in Eclipse

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:

Create web application using Maven in Eclipse

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.

Create web application using Maven in Eclipse

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:

Create web application using Maven in Eclipse

then click Next button:

Create web application using Maven in Eclipse

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:

Create web application using Maven in Eclipse

Click Finish to complete.

Result:

Create web application using Maven in Eclipse

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.

Result:

Create web application using Maven in Eclipse

 

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment