When I use eclipse to create webapp with maven using "maven-archetype-webapp", it creates only Servlet 2.3. How can I create Servlet 3.0?
There is still no good way of doing this.
Eclipse is parsing web.xml to indentify project's facet and therefore servlet version.
To achieve servlet 3.0 web app in eclipse follow these steps:
Using Eclipse only:
New -> Project -> Mvn Project
Replace web.xml file with new 3.0 version:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Archetype Created Web Application</display-name>
</web-app>
Close project and delete it from the workspace (don't delete files on the disk)
import -> Existing Maven Project
Using MVN commandline + Eclipse
Create MVN project of maven-archetype-webapp
mvn archetype:generate
-DarchetypeGroupId=org.apache.maven.arechetypes
-DarchetypeArtifactId=maven-archetype-webapp
-DarchetypeVersion=1.0
-DgroupId=<my.groupid>
-DartifactId=<my-artifactId>
Replace contents of web.xml as in eclipse method point 2.
The easiest way I've found is to create a Dynamic Web Project in eclipse and then convert it to Maven project:
The project will be configured with the latest version of the servlet
Then add the servlet and jsp dependencies to pom.xml:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With