When creating a maven project in Eclipse, the archetypes use ridiculously outdated default parameters, such as Java 1.5 or Dynamic Web Module 2.3.
When using the webapp archetype, a few of the default settings can be corrected, using the following pom.xml:
<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>de.test</groupId> <artifactId>MyService</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>MyService Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <!-- JUnit Files --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>MyService</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
Next replace your web.xml with the following web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"> </web-app>
Next switch to the Navigator View, open org.eclipse.wst.common.project.facet.core.xml from your .settings folder and replace
<installed facet="jst.web" version="2.3"/>
with
<installed facet="jst.web" version="3.1"/>
Now right click your project and click on Maven -> Update Project.
Go to your Navigator again and
- create the folder java under src/main
- create the folder java under src/test
This should fix most of the problems and enable you to use Maven in Eclipse.