342
votes

I am using maven to create a dynamic webapp in Eclipse. I added some folders like src/test/java and src/test/resources. Also I changed the library in Java Build Path to obtain the JavaSE-1.7. It's all OK up to here.

When I tried to change the Projects Facet Dynamic Web Module something went wrong. I had change the Java to 1.7 in the same place. And it still told me, cannot change version of project facet Dynamic Web Module to 3.0.

I have changed everything that would effect the changing I think.

30
OK. I am sorry about that. The archetype is maven-archetype-webapp when I create the New Maven Project, and the Dynamic Web Module is 2.3 in the Project Facets after I created the project. I want to change the version of the Dynamic Web Module to 3.0, and I got 'Cannot change version of project facet Dynamic Web Module to 3.0'EdgarZeng
In Eclipse Kepler, when I right-click on the 'Dynamic Web Module' facet, it displays an 'Unlock' option. After un-locking, I was able to change the facet version. for info only.Jonathan
Is this a bug for eclipse ?CDT

30 Answers

320
votes

I updated my web.xml

<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 ...

610
votes

Another way is to edit the project facet configuration file itself: org.eclipse.wst.common.project.facet.core.xml

Change the dynamic web module version in this line to 3.0 - <installed facet="jst.web" version="2.5"/>

And then:

  1. Right-click on the project (in the Project Explorer panel).
  2. Select Maven » Update Project (or press Alt+F5)

You'll find this file in the .settings directory within the Eclipse project.

180
votes

I think I had the same problem as you. My web.xml had version 2.5 while the project had the (right-click on Project-> Properties-> Project Facets->) Dynamic Web Module 2.3.

Although I tried to change the version from 2.3 to 2.5 ECLIPSE did not permit it. Solution: I removed the check mark under the heading Dynamic Web Module, I saved and I had Update Project. Automatically re-awakening is entering the box with the correct version. I use Eclipse Kepler.

p.s.: look at the comments of Jonathan just below, very useful.

52
votes
  1. Click on your project folder.
  2. Go to Window > Show View > Navigator
  3. Go to Navigator and expand the .settings folder
  4. Open org.eclipse.wst.common.project.facet.core.xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <faceted-project>
      <fixed facet="wst.jsdt.web"/>
      <installed facet="jst.web" version="2.3"/>
      <installed facet="wst.jsdt.web" version="1.0"/>
      <installed facet="java" version="1.8"/>
    </faceted-project>
    
  5. Change the version like this <installed facet="jst.web" version="3.1"/>

  6. Save
  7. Just update your project. Right Click on The Project Folder > Maven > Update Project > Select the Project and click 'Ok'

Just this worked to me.

45
votes

I had the same issue and I even tried to remove the project and add it again. What did the trick was to remove the .settings directory.

27
votes

Delete

.settings 
.classpatch 
.projejct 
target

and import again the maven project.

23
votes

What worked for me:

  1. Change the Java to 1.8 (or 1.7)

In your POM - you have to set compiler plugin to version 1.8 (or 1.7) in <build> section:

  <build>
    ...
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.0</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>  
      </plugins>    
  </build>

Ensure that change Java Build shows 1.8. If it does not - click EDIT and select what it should be.

enter image description here

  1. Modify web.xml so 3.0 is referenced in version and in the link

enter image description here

  1. Ensure you have Java set to 1.8 in Project Facets

enter image description here

  1. At this stage I still could not change Dynamic Web Module;

Instead of changing it:

a) uncheck the Dynamic Web Module

b) apply

c) check it again. New version 3.0 should be set.**

enter image description here

After applying and checking it again:

enter image description here

Hope this helps.

15
votes

Right click the projectProperties; in Project Facets, deselect Dynamic Web Module (version should be 3.1) and deselect JavaServer Faces (version is 2.2).

Change this:

<web-app version="3.1" 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">

to this:

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

Then remove the prefix before param-name and the like.

Finally, Maven -> Update project.

8
votes

you please open the Navigator view and following step

  1. (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.
  2. Change the dynamic web module version in this line to 2.5 -
  3. Change the Java version in this line to 1.5 or higher - .
6
votes

Open web.xml from project structure http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> Servlet 3.0 Web Application

and update web.xml file for example change version = "2.5"

Also change the org.eclipse.wst.common.project.facet.core.xml file from your project .settings file Follow the steps 1. Window > Show View > Other > General > Navigator

  1. There is a .settings folder under your project directory

  2. Change the dynamic web module version in this line to 2.5 4.Change the Java version in this line to 1.5 or higher

Now refresh your project and get set to run on your server.

Do follow the blog for the solution http://scrapillars.blogspot.in/2014/02/how-to-change-project-facet-in-eclipse.html

The solution is produced with image illustrations

6
votes

Best and simple steps solved this problem for me is 1) Properties -> Project Facets -> Deselect/unmark the check box of Dynamic Web Module -> Apply 2)Now change to the desired version Apply 3)Check the Dynamic web Module check box.. --Now your are done--

4
votes

Their is one more way to resolve this problem (check it out hope it will help you to solve your problem)

PROBLEM

Cannot change version of project facet dynamic web module 2.3 to 3.0

SOLUTION

  1. Go to your project location (ex.-D:/maven/todo)
  2. go to .setting folder
  3. check for this file: org.eclipse.wst.common.project.facet.core.xml
  4. open the file and change "jst.web" property from 2.3 to 3.0, and save
  5. Right click on project refresh the project and update maven
  6. Done!!!....
3
votes

The web.xml trick works because you're now explicitly telling WTP that you are using that specific servlet version, regardless of what the container supports.

In my case, I am using the annotation config within a Maven project and I do not have a web.xml file. It turns out that in the absence of a web.xml, WTP looks at your Maven dependencies to determine what Servlet version to use. In my case, I had defined the following:

<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>7.0</version>
  <scope>provided</scope>
</dependency>

Changing it to 6.0 fixed the problem and it's now using Servlet 3.0 instead of 3.1, which is the default for JavaEE 7. Since I had to go from Tomcat 8 to Tomcat 7, Tomcat 7 only supports the JavaEE 6 Web profile. Now things work wonderfully.

3
votes

I had the same issue, editing web.xml as well as changing file in .settings folder alone didn't help. My solution was to directly point maven compiler plugin to use the desired java version by editing pom.xml:

  <build>
    ...
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>    
  </build> 

Now run Maven->Update project and after that you can change servlets version in properties->project facets->Dynamic Web module version or, as written earlier, by manually editing org.eclipse.wst.common.project.facet.core.xml in .settings folder of your project.

2
votes

In my case the web.xml was referenced by a dtd. After I changed this to xsd reference like the one posted by Sydney it worked.

2
votes

I had the same issue ,deleting the .settings folder resolved the issue

1
votes

My solution to the problem that didn't allowed me to change the version of project facet Dynamic Web Module in Eclipse (Mars) was:

  • Disable Maven Nature
  • Ensure that the web.xml namespaces point to right version
  • Re-enable Maven Nature
  • Maven » Update Project (or press Alt+F5)
1
votes

If answer by Sydney still doesn't help then try below. After following Sydney's answer, goto Properties > Projects Facets deselect Dynamic Web Module and then change the version to match your web.config and then select again. Apply > Save Then Maven Update.

web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="Web_App_1" version="3.1">

<display-name>JavaServerFaces</display-name>

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>jsfs/hello.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>jsfs/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

1
votes

I tried many of the answers here, but none of them worked for me. Then I found an article about my problem here. I thought of sharing it here too.

Below are the steps taken in brief.

  1. Set Compiler compliance level.
  2. Update project facet
  3. Update installed JRE from preferences
  4. Adding configuration in pom.xml to use java 1.7 and finally
  5. updating project from Maven.
1
votes

For a maven eclipse web project, changing dynamic web module version needs to check three places. If one uses eclipse, and after you have checked the following: 1) web.xml

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

2) maven:

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>   ## ensure you have tomcat 7 not other version
</dependency>

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.0</version>
      <configuration>
            <source>1.7</source> ## at least 6
            <target>1.7</target>
      </configuration>
</plugin>

3) eclipse build path and compiler version is 1.7

you still have an error marker at maven:

cannot change version of project facet dynamic web module to 3.0 one or more constrants have not been satisfied

Then you can: uncheck the dynamic web module, and recheck it. I think it is because .settings of eclipse file is corrupted somehow. About the second tip tomcat which version is a good note.

1
votes

I got this error when I try to convert a general Java Project to Maven Project.

What I did was to determine the Java compiler version which is required by my project. For my project, the minimum Java version is 1.8.

By lowering the version to anything lower than 1.8 my IDE will start complaining that it does not recognize a bunch of imported libraries, hence I determine mine minimum Java version as 1.8

1. Right click your project
2. Go to Properties
3. Left hand-side panel, click "Project Facets"
4. For Java, set the version according to your minimum version

enter image description here

Now make sure the Java compiler version uses the same Java version as what you have set in Project Facets.

1. Right click your project
2. Go to Porperties
3. Left hand-side panel, click "Java Compiler"
4. Make sure Java Compiler version is the same. 
5. If it is not the same, change the version. (Uncheck "Use compliance from execution environment' if needed to make the changes.

enter image description here

After the changes, the error should be resolved. If the error is still there, right-click project -> Maven -> Update Project

0
votes

Doing maven update or reimporting the project did not help. @Sydney's answer is right; in addition I have to recreate the project in different workspace as said in JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer

0
votes

Open the org.eclipse.wst.common.project.facet.core.xml file and change the jst.web version to 3.0. Also update the web.xml to version 3.0. Save and update the project. Hope this helps. I am using Eclipse Juno

0
votes

This is a variation on pagurix's answer, but using Eclipse Mars.

Change your web.xml file to web.bak

Ignore the errors, we'll regenerate it next.

Go into project properties -> project facets and set the Dynamic Web Module version to what you need. Eclipse now allows you to save.

Now right-click on the project. Choose Java EE Tools -> Generate Deployment Descriptor Stub.

This creates a new web.xml with the required version.

Open the new web.xml and copy across the XML header and the complete web-app opening tag to your original web.bak, delete the new web.xml and rename web.bak back to web.xml.

Done.

0
votes

Mine was Web Module 3.0 in web.xml, but in properties>Dynamic Web Module It was on 3.1

I changed the web.xml to 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

after this change, do: right click on project>Maven>Update Project...

0
votes

This Problem With version right click on the project->properties->Project Facets->right click on Dynamic Web Module->unlock it-> uncheck->select 2.5 version->Apply->Update the maven

0
votes

I resolved the issue by modifying web.xml with correct version,xsd locations and modifying org.eclipse.wst.common.project.facet.core.xml with correct version and doing maven update.

0
votes

updating maven worked for me

select project then press ALT+F5 then select project click ok

0
votes

I had the same symptom with a different cure. I was trying to upgrade my JSF 2.2.4/Spring 3.0 webapp to JSF 2.3 in order to enjoy the new JSF websocket hooks there and Eclipse (actually STS) would not cooperate. In Eclipse's Project Facets, JSF 2.3 never became available until I edited directly the org.eclipse.wst.common.project.facet.core.xml file as directed in previous answers - the highest it would go was 2.2.

Here are the hoops I jumped through. I don't know that all of these were necessary because I fundamentally don't understand all this configuration.

In Eclipse I frequently got a scary warning, "Modifying a faceted project when implementations of one or more installed facets are not available can potentially result in a corrupted project. Are you sure you want to proceed?" This prompted me to do more frequent commits but no corruption occurred.

  1. Upgrade JDK from 1.7 to 1.8 in POM, Eclipse compiler, and Eclipse Project Facets.
  2. Update the following Maven dependencies:

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

    ... to:

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

... and ...

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.4</version>
    </dependency>

... to:

    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.3</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>2.0</version>
    </dependency>

I had to update my web.xml namespace declarations from:

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

... to:

<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" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

I had to update Project Facets -> Dynamic Web Module from 2.5 to 3.0. I tried 3.1 but got errors.

In this process I frequently got the error in the title of this post, "Cannot change version of project facet Dynamic Web Module to 3.0" and Eclipse refused to compile the project or offer JSF 2.3 in the Project Facets. When I edited the org.eclipse.wst.common.project.facet.core.xml file as directed the errors disappeared, Eclipse offered JSF 2.3 in Project Facets, and the project compiled and ran fine on Tomcat 9.0.8. However, Project Facets still warned "Implementation of version 2.3 of project facet jst.jsf could not be found. Functionality will be limited." I suspect this simply means that autocomplete and other Eclipse conveniences will not be available because it cannot find the JSF 2.3 implementation declared in my POM.

Hope this helps someone. Google searches yielded only this post by Ali Bassam and indirectly BalusC which helped.

0
votes

I had the same problem - I just removed the project from my workspace, then cleaned up the "eclipse files/folders, for example: .project, .settings, etc) then imported the maven project again, it worked.