Apr 112016

ADM

Create a Web Application with Maven in Eclipse

  • 11 April 2016
  • ADM

 

Create a Web Application with Maven in Eclipse - images/logos/eclipse.jpg

 

This tutorial will follow the steps to create a webapp with maven in eclipse.

These tools were used here:

  • Apache Maven 3.2.2
  • Java 1.8.0_40
  • Eclipse Mars
  • Tomcat 8

Step 1 - New Project

Create a new project from Eclipse by selecting Maven --> Maven Project.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject1.png

Step 2 - Location

Select the destination location. For this tutorial will use the default Workspace location.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject3.png

Step 3 - Archetype

Search for the maven-archetype-webapp, select and click Next.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject2.png

Step 4 - Add details

Fill out below details and click Finish.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject8.png

The project structure will look like the following image.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject4.png

Step 5 - error fix (optional)

If you see error "The superclass javax.servlet.http.HttpServlet" was not found on the Java Build Path then add below maven dependency.

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.1</version>
    <scope>provided</scope>
</dependency>

OR add Apache Tomcat to your Targeted Runtimes.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject5.png

Step 6 - setup the server

Add the project to the server.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject6.png

Step 7 - test

Open the link in the browser.

Create a Web Application with Maven in Eclipse - /images/mavenNewProject7.png

Now you are ready to go.