In a previous article, we have discussed how to create a simple maven project in eclipse. In this article, we will show you how to create a web project or application using maven in Eclipse IDE.
Let me list out what are tools and technologies that I have used to create a web project or application using maven in Eclipse IDE.
Tools and technologies used
- IDE – Eclipse Neon
- JDK – 1.8
- Maven – 3.5.3
- Apache Tomcat – 8.5
- Servlet API – 3.1.0
Let’s start step by step to create a web project using Maven in Eclipse IDE.
Step-1
- Open Eclipse
- Click on File -> New -> Maven Project

Step-2
- Don’t select a simple project as shown in below diagram
- Select default Workspace location
- Click on Next

Step-3
Select the Maven archetype as maven-archetype-webapp
and click on next.

Step-4
Provide GroupId
,ArtifactId
, package
and click on finish.
- GroupId: com.favtuts.maven-demo
- Artifact Id: maven-eclipse-web-project
- package: com.favtuts.mavenwebapp

Step-5
And you are all set. You should see a new Project in Eclipse with below structure.

Now, let’s test this web project by adding simple Servlet and deploy on tomcat server.
Step-6
Open pom.xml
file and add servlet API dependency and maven compiler plugin as:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.favtuts.maven-demo</groupId> <artifactId>maven-eclipse-web-project</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>maven-eclipse-web-project Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/jsp-api --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>maven-eclipse-web-project</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
Step-7
Now create a SimpleServlet
class under com.favtuts.mavenwebapp package and write the following code in it.
package com.favtuts.mavenwebapp; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /* * Servlet implementation class SimpleServlet */ @WebServlet("/hello") public class SimpleServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); resp.getWriter().write("Hello World! Maven Web Project Example."); } }
Step-8
Let’s Build the project using the following maven command.- mvn clean install
To execute the about maven command in Eclipse IDE, Click on 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.
[INFO] Scanning for projects... [INFO] [INFO] ----------< com.favtuts.maven-demo:maven-eclipse-web-project >---------- [INFO] Building maven-eclipse-web-project Maven Webapp 0.0.1-SNAPSHOT [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-eclipse-web-project --- [INFO] Deleting /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-eclipse-web-project --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ maven-eclipse-web-project --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 1 source file to /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-eclipse-web-project --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ maven-eclipse-web-project --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-eclipse-web-project --- [INFO] No tests to run. [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ maven-eclipse-web-project --- [INFO] Packaging webapp [INFO] Assembling webapp [maven-eclipse-web-project] in [/home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/target/maven-eclipse-web-project] [INFO] Processing war project [INFO] Copying webapp resources [/home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/src/main/webapp] [INFO] Webapp assembled in [32 msecs] [INFO] Building war: /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/target/maven-eclipse-web-project.war [INFO] WEB-INF/web.xml already added, skipping [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ maven-eclipse-web-project --- [INFO] Installing /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/target/maven-eclipse-web-project.war to /home/tvt/.m2/repository/com/favtuts/maven-demo/maven-eclipse-web-project/0.0.1-SNAPSHOT/maven-eclipse-web-project-0.0.1-SNAPSHOT.war [INFO] Installing /home/tvt/github/java-maven-tutorials/maven-eclipse-web-project/pom.xml to /home/tvt/.m2/repository/com/favtuts/maven-demo/maven-eclipse-web-project/0.0.1-SNAPSHOT/maven-eclipse-web-project-0.0.1-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.615 s [INFO] Finished at: 2022-06-24T20:14:01+07:00 [INFO] ------------------------------------------------------------------------
Step-9
Let’s deploy our web project into tomcat. Let’s first configure tomcat server in Eclipse IDE via server section. Once deployment is a success then Open a browser and type http://localhost:8080/maven-eclipse-web-project/hello URL in address bar.

That’s all. I hope you understood the flow of creating a web project using Maven in Eclipse. Do comment if you need any help or issues.
Download Source Code
$ git clone https://github.com/favtuts/java-maven-tutorials.git
$ cd maven-eclipse-web-project
$ mvn clean installRun on Tomcat server
Access: http://localhost:8080/maven-eclipse-web-project/hello