Thursday, July 22, 2010

Adding servlet support to the Maven webapp archetype

Today I wanted to create a servlet and used the m2eclipse plugin for Eclipse to create a web application based on the available Maven webapp archetype.

When using the archetype you will miss some essential jars and cannot create a Java 5 servlet. So I did the following:

1. adjust the pom: add dependency

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

2. adjust the web.xml: adjust the header

<?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_2_5.xsd"
         version="2.5">

3. open the properties of the project and under Java Compiler change the compliance level to 1.5

No comments:

Post a Comment