With the Servlet 3.0 API, it's possible to have web archives only with annotated servlets and omit a web.xml
file, or at least omit the configuration of the application within a web.xml
file.
As usual, you will find the code for this recipe at the GitHub location at https://github.com/jgoodyear/ApacheKarafCookbook/tree/master/chapter4/chapter4-recipe9.
As with the Building a standard web project to host in Apache Karaf recipe, we just build another WAB bundle. Only this time, we have a web.xml
file containing only the definition for the welcome-file-list
method and annotated servlets:
The first step is defining the
web.xml
file. This can be done as follows:<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"> <...