reset password

Maven Web Application

Create an Maven web application in Eclipse using the maven-archetype-webapp archetype and do the following:

1. Change web.xml to the following:


<?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="sham">


    <display-name>sham</display-name>

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

</web-app>

This change basically says that our project requires an application server that supports the Servlet 3.0 Specification.

2. Add the following to pom.xml (right after <finalName>):

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>

This change says that the project requires JDK 1.7 (or above) to compile, and the compiled class files are compatible with JVM 1.7.

3. Add the following dependencies to pom.xml:

  • javax.servlet:javax.servlet-api:3.0.1 (set the scope of the dependency to provided)
  • javax.servlet:jstl:1.2

This allows us to use classes like HttpServletRequest and HttpServletResponse in our Java code, and use JSTL in the JSPs. And since this is SHAM - Spring and Hibernate at the Minimum, feel free to remove the JUnit dependency because we won't be doing any unit testing.

4. Add a folder src/main/java. This is where the Java code would go.

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

This page has been viewed 20221 times.