35
votes

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?)

10

10 Answers

102
votes

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

13
votes

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.

6
votes

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.

3
votes

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

2
votes

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
votes

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

1
votes

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 :)

0
votes

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"
0
votes

@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

0
votes

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