37

I've inherited a Java web app from another company. I'm trying to load it into Eclipse (via Import Maven Project), and getting an error that says "Cannot change version of project facet Dynamic Web Module to 2.5".

I've been poking around a little, and one thing I'm finding is that the web.xml file starts with

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

and the pom.xml specifies a dependency of

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

but the .settings folder contains a file with this

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="java" version="1.6"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

and I suspect that the 3.0 specified here is conflicting with the 2.5 specified elsewhere. Is that likely to be the case? Is there any way this combination of settings could NOT result in errors? (Older version of Eclipse, eg?)

joelt
  • 2,672
  • 2
  • 24
  • 32
  • Possible duplicate of [Cannot change version of project facet Dynamic Web Module to 3.0?](https://stackoverflow.com/questions/18122336/cannot-change-version-of-project-facet-dynamic-web-module-to-3-0) – Paullus Nava Oct 17 '17 at 19:52

10 Answers10

104

short version

Try this:

  • Deselect the Dynamic Web Module in your project facets. Right click the Project -> preferences -> Project Facets
  • Then run Maven -> Update Project again.

Long Version

I've had this problem a number of times while learning some eclipse dynamic web/spring stuff and none of the other solutions fixed my issue reliably or helped me understand what was causing the issue. I think I am beginning to.

So it appears that when you run a Maven -> Update Project, m2e (I assume) is ADDING the Dynamic Web Module to the Project Facets. Adding is the key word here. So when I went in and updated web.xml from [...] http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd" version="2.3"> to [...] http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

I got the error "Cannot change version of project facet Dynamic Web Module to 2.5."

Same was true for 3.0 when I tried that.

It appears m2e is capable of adding this to your project but like the error says it is unable to change it once it is set. So simply deselect it in the project facets page. Hit O.K. to save your preferences and run Maven Update again.

Eclipse Project Facets Dynamic Web Module

You shouldn't need to include javax.servlet in your pom.xml if you have a server (like tomcat) facet added.

Servlet-Api included in libraries

TheSporkboy
  • 1,759
  • 1
  • 13
  • 13
  • Thanks. I had this problem upgrading JSF from 2.0 to 2.2. Had to remove first the JSF, then the Dynamic Web Module facet. Changed the also. (The JSF spec uses version="2.0" in the 2.2 release. Very confusing.) – Mike Feb 23 '15 at 04:14
  • Thanks, this was very helpful and trivially easy. – Tony B Mar 19 '16 at 20:59
  • This was a new one for me. Thanks for posting! – James Drinkard Nov 10 '17 at 16:02
  • I used to fix this by searching through all my eclipse config files and replacing 2.3 with 2.5. It worked about 50% of the time, this is much better – Brent Sandstrom May 30 '18 at 15:51
  • This worked for me too. In my case though eclipse said it cannot remove this facet because its needed for JSF facet. So i removed them both and executed Maven Update Project (ALT+F5). – JSamir Jan 22 '19 at 09:36
14

See Cannot change version of project facet Dynamic Web Module to 3.0?

Close the project, and directly update file 'org.eclipse.wst.common.project.facet.core.xml' located in the .settings folder of the project.

Community
  • 1
  • 1
JackDev
  • 11,003
  • 12
  • 51
  • 68
  • 6
    Yes, it works, but you don't need to close the project. Just press Ctrl + Shift + R in Eclipse, open `org.eclipse.wst.common.project.facet.core.xml` and update the line `` with the new version. – ROMANIA_engineer Nov 13 '15 at 10:01
6

My guess is the original authors manually changed the Project Facets of the Eclipse project after the initial import and never ran Maven | Update after that.

Anyway, for Maven projects, it's good practice not to commit any Eclipse metadata (i.e. .classpath, .project, .settings/) to SCM and to let m2e generate them on import.

So I'd recommend to copy your project structure, delete all Eclipse metadata from the copy and then import via m2e.

If there are still any errors on import, than at least you might get a hint where the original authors tweaked the defaults, so you'll know where to start cleaning up.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
  • removing the .classpath, .project, .settings helped me to customize project facets. – Jay Jun 01 '15 at 21:36
  • Removing the project from eclipse and mentioned files then importing back the project as a maven project worked for me here! Thanks. – Jorge Campos Jun 30 '15 at 14:24
3

Open the Navigator view (Window > Show View > Other > General) and find that there is a .settings folder under your project, expand it and then open the file “org.eclipse.wst.common.project.facet.core.xml”, make the below changes and save the file.

Change the dynamic web module version in this line to 2.5 – <installed facet=”jst.web” version=”2.4″/>

Change the JSF version in this line to 2.0 – <installed facet=”jst.jsf” version=”1.1″/>

Change the Java version in this line to 1.5 or higher – <installed facet=”java” version=”1.5″/>.

After this changes you can change the version of Project facet Dynamic Web Module from the project properties; without giving you this warrning

Hatem Badawi
  • 536
  • 4
  • 9
2

In my case I wanted to change dynamic facet form 2.3 to 3.1.

What help me was one number change in may web.xml

From :

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app  > 
  <display-name>Archetype Created Web Application</display-name>
</web-app>

TO :

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_5.dtd" >

<web-app  > 
  <display-name>Archetype Created Web Application</display-name>
</web-app>

And then go to properties -> Project Facets -> Uncheck the Dynamic Web Module -> OK

Updated Maven project.

1

My solution was:

Change header in my web.xml:

I put:

<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">
    <display-name>Servlet 3.0 Web Application</display-name>
</web-app>

and then just Maven -> Update Project

Gere
  • 2,114
  • 24
  • 24
1

This blog post helped me very well: How to fix Cannot change version of project facet Dynamic Web Module to 3.0 Error in Eclipse.

This post explains that if right click> properties> project facets> changing the version of Dynamic Web Module to the correct one does not help, try the following: right click> properties> resources> go to the address you see in location part. Open the org.eclipse.wst.common.project.facet.core file and change the jst.web version as you need. Refresh the project. It should work :)

user1419243
  • 1,655
  • 3
  • 19
  • 33
0

Note that current schema location for web-app is:

xsi:schemaLocation="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd"
CubeJockey
  • 2,209
  • 8
  • 24
  • 31
0

@TheSporkboy is almost correct. I ran into this today and after some fiddling with configuration the solution was as follows:

1- Change the setting for Dynamic Web Module in the Project Facets to latest 3.1

2- Open up the project's web.xml from .../web-app_2_5.xsd to .../web-app_3_1.xsd

3- Update Maven project

AlexH
  • 1
  • 1
0

you must change both files!

First step: close eclipse

Second step: change facet label "jst.web" in org.eclipse.wst.common.project.facet.core.xml

And finally, change the version of xsd in web.xml

It works to me

jirou
  • 11
  • 3