reset password

Maven Web Application

Create a Maven project in Eclipse. During project creation, choose the Create a simple project option as shown in the screenshot below:

New Maven Project

And on the next screen, fill out Group Id, Artifact Id, and change Packaging to war. You can leave all other fields as is.

1. After the project is created, add the following to pom.xml (inside <project> and after <packaging>):

  <build>
    <finalName>springmvc</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.0.1</version>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
      </dependency>
  </dependencies>

These changes specify that the project requires JDK 1.7 and add the following dependencies:

  • javax.servlet:javax.servlet-api:3.0.1
  • javax.servlet:jstl:1.2

2. Create a folder WEB-INF under /src/main/webapp, then create a file web.xml under WEB-INF with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0" id="springmvc">


    <display-name>SpringMVC</display-name>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

3. Create an index.html and place it under /src/main/webapp. This file will serve as the entry page to the project (i.e. the page displayed when you run the project in Eclipse). The content of index.html is up to you.

4. Right click on the project and select Maven -> Update Project...

Now you have set up a Maven web project to which you can add your code.

This page has been viewed 20209 times.