I tried to use Servlet 4.0 namespace. The application worked well, but IDEA detects an error: "Element web-app" must be declared".
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
...
...
</web-app>
Snapshot (I can't post images directly.)
When I changed the version to 3.1, it worked well:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
According to Java EE: XML Schemas for Java EE Deployment Descriptors# Using Java EE Schemas:
All Java EE 7 and newer Deployment Descriptor Schemas share the namespace http://xmlns.jcp.org/xml/ns/javaee/. Each schema document contains a version attribute that contains the version of the specification. For example, the XML Schema document for the Servlet specification contains the version attribute value "3.1", pertaining to the specific version of the specification as well as the schema document itself.
Is version="4.0"
not supported? I use IntelliJ IDEA 2017.2.5 + javax.servlet-api 4.0 + Apache Tomcat v9.0.1.
Updated: I found an example of web.xml(in apache-tomcat-9.0.1/webapps/examples/WEB-INF/web.xml
):
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">