Eclipse irreversible Dynamic Web Module 4.0 selection; Tomcat 9 doesn't support it

I reproduced the problem in the same environment as yours. When I tried to regress from 4.0 back to 3.1 I got the following error:

CannotDowngradeTo31

This blog provided the solution (which is a bit of a hack but it works):

  • Edit the file org.eclipse.wst.common.project.facet.core.xml in the project's .settings directory.
  • For the line containing facet="jst.web" version="4.0", change the version to 3.1.

Also see this SO question: Dynamic Web Module 3.0 -- 3.1


A couple of related issues:

  • It looks like something else may not be quite right with your setup to be getting that error "Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules". Is your project configured to use Servlet 4.0? For my Maven project I had to add this dependency to the POM for Servlet 4.

  • Even after changing the Dynamic Web Module version to 3.1 my web app continued using version 4.0, so I'm not sure what that facet achieves.


My solution is a response to this message:

Dynamic Web Module 4.0 cannot be uninstalled.

1 - So; if you can't uninstall Dynamic Web Module (i repeat: "Uninstall" not "change its version"), You can first edit in your project directory the file: .settings/org.eclipse.wst.common.project.facet.core.xml and manually uninstall it by removing this line:

<installed facet="jst.web" version="4.0"/>

2 - After this, if you want to use dynamic web module 4.0, be sure that you use at least in your facets java 1.8 inside the same file .settings/org.eclipse.wst.common.project.facet.core.xml

<installed facet="java" version="1.8"/>

Or you can also change it in your "project Facets configuration" panel

3 - If the problem persist, take a look at your pom files and verify didn't force java version to 1.7, you should have these properties

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

Remember to update your project if you change your pom file: Maven > Update Projects

4 - Finally, if you still can't use Dynamic Web Module 4.0, juste choose between deleting your WEB-INF\web.xml file which can have a configuration for another dynamic web version like this:

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

Otherwise you can manually change the supported version:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
...

return to the Project Facets configuration panel, a try once again to choose Dynamic Web Module 4.0, it should work

Hope this help.