14

I'm using Eclipse Oxygen.2 (4.7.2) on Windows 10 with Java 8. I have a faceted project I run inside Eclipse using Tomcat. I had been using Tomcat 8.5, but on a new system I upgraded to Tomcat 9. Of course I removed the Tomcat 8.5 server and server runtime within Eclipse, and added back a Tomcat 9 server runtime.

Before adding the Tomcat 9 server within Eclipse I verified the Project Facets of my project. I saw that Dynamic Web Module was set to "3.1", but that now "4.0" was available. I changed to "4.0", figuring this would give me access to newer APIs.

I then tried to add the Tomcat 9 server. During the process, at "Add and Remove" it asks me which projects I want to add to be configured for the server. I selected my web project, but Eclipse said: "Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules".

Now as far as I know that's exactly what I'm using. But the only thing I had changed was the Dynamic Web Module. So I went back to my project configuration and tried to change "Dynamic Web Module" back to "3.1". Eclipse tells me:

Cannot change version of project facet Dynamic Web Module to 3.1.

Um… so I'll just remove it. I unchecked the box next to "Dynamic Web Module", and Eclipse tells me:

Dynamic Web Module 4.0 cannot be uninstalled.

Well that's a fine kettle of fish. I can't deploy my project to Tomcat, apparently because of the Dynamic Web Module. I can't change the Dynamic Web Module back to what it was. What do I do? Where does the problem lie?

I opened Eclipse Bug 530844 to see if I can get some reasons for this behavior.

Garret Wilson
  • 18,219
  • 30
  • 144
  • 272
  • Usually, unlock, change version and relock will work - but this ended up working [eclipse or spring suit error maven project dynamic web module cannot be changed](https://stackoverflow.com/questions/36056485/eclipse-or-spring-suit-error-maven-project-dynamic-web-module-cannot-be-chan) – JGlass Feb 06 '18 at 19:34
  • Re "Of course I removed the Tomcat 8.5 server and server runtime within Eclipse"...why would you need to do that? Both Tomcat servers can exist within Eclipse (assuming you had installed them to separate directories). – skomisa Feb 07 '18 at 02:51
  • @skomisa this was a new system install and I didn't even bother installing Tomcat 8.5—that's why I removed that server and runtime from Eclipse. (I brought over my existing project to the new machine.) – Garret Wilson Feb 07 '18 at 15:08
  • @GarretWilson OK, got it. – skomisa Feb 07 '18 at 15:57

4 Answers4

12

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.

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • My project doesn't specifically configure the servlet version. It uses `javax.ws.rs-api:2.0.1` and `resteasy-jaxrs:3.1.0.Final`. Will this not work with Tomcat 9? Why would I have to add a dependency for Servlet 4? Why would my project be required to use Servlet 4? – Garret Wilson Feb 07 '18 at 15:06
  • No, you don't **need** a dependency for Servlet 4 for your app, but by setting Dynamic Web Module to 4.0 weren't you telling Eclipse that your project **was** using Servlet 4.0? (I suspect I'm missing the point you are making.) Regardless, the answer to your question is to correct that version in core.xml. – skomisa Feb 07 '18 at 15:56
  • To be clear, I didn't get the error you saw "Tomcat version 9.0 only supports...", and I was wondering if that was because the web app for which I changed Dynamic Web Module to 4.0 really was using Servlet 4.0, whereas yours was not - that's all. – skomisa Feb 07 '18 at 16:02
  • "…by setting Dynamic Web Module to 4.0 weren't you telling Eclipse that your project was using Servlet 4.0?" No, by setting Dynamic Web Module to 4.0, I was telling Eclipse that I wanted to use Dynamic Web Module 4.0. I assume that it is better than Dynamic Web Module 3.1 and _supports_ later servlet APIs but doesn't require them, just like I assume that Tomcat 9 is better than Tomcat 8 and supports later servlet APIs but doesn't require them. Maybe my assumption is incorrect. – Garret Wilson Feb 07 '18 at 19:04
  • 1
    Your solution for manually editing `org.eclipse.wst.common.project.facet.core.xml` works! I'll wait to see if there are more "official" ways to do it directly, and if not I'll mark your answer as correct. Thank you. – Garret Wilson Feb 07 '18 at 21:51
3

For me, this issue went away after removing the dependency below from my pom file.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.0</version>
    <scope>provided</scope>
</dependency>

hope that helps

masber
  • 2,875
  • 7
  • 29
  • 49
2

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.

Benfarhat
  • 183
  • 7
0

I downgraded javax.servlet-api to 3.1.0 ;

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

Then Edited as per @Skomisa's above comment;

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.

Note - Update maven project and check to reflect changes.

ThivankaW
  • 511
  • 1
  • 8
  • 21