How to create a web project using maven in eclipse

Posted on March 17, 2017

In this post, we will show you how to create a dynamic web project using maven in Eclipse IDE.

Tools and technologies used -

  • Eclipse Mars.2 (4.5.2)
  • Maven 3.3.3
  • JavaSE 1.8
  • Servlet API 3.1.0
  • Apache Tomcat 7.0.47 (Embeded)

Let’s start step by step to create a web project using maven in eclipse.

Step #1

Go to New menu → Other..MavenMaven Project and click on Next.


Step #2

In New Maven Project wizard, select Create a simple project and click on Next.


Step #3

In next wizard, add project information as shown below and click on Finish.

Learn more about Maven naming conventions on groupid artifactId and version.



Step #4

Open pom.xml file and add servlet dependency and Tomcat maven plugin in it as shown below.


<project xmlns="" xmlns:xsi=""

    <!-- Servlet API -->


      <!-- Embedded Apache Tomcat required for testing war -->


After changes in pom.xml file, update the maven web project.

To update web maven project, right click on maven-web-project-example project → Maven → Update Project.


Step #5

Review the maven web project structure.


Step #6

Now create a HelloWorldServlet class under com.boraji.tutorial.servlet package and write the following code in it.

package com.boraji.tutorial.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 * @author imssbora
public class HelloWorldServlet extends HttpServlet {

   private static final long serialVersionUID = 1L;

   protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
         throws ServletException, IOException {
      resp.getWriter().write("Hello World! Maven Web Project Example.");

Step #7

Build the project using the following maven command.

mvn clean install

To execute the about maven command in Eclipse IDE, go to Run menu → Run Configuration.. to create a new configuration.

In Run Configuration Wizard, double click on Maven Build and provide the configuration information (Name, Base directory and Goals) as shown in the below image.


Now click on the Run and monitor the output in console.



Step #8

Run embedded tomcat server using the following command.

mvn tomcat7:run

To execute the about maven command in Eclipse IDE, create a new configuration as shown in the below image.


Now run configuration to start tomcat server. The console output will look like as shown in the below images.


Step #9

Open browser and type http://localhost:8080/hello URL in address bar.


Download Sources