22
votes

I tried few things, but still this problem persists. I am using Eclipse Kepler. I get following error on importing maven project

JavaServer Faces 2.2 can not be installed : One or more constraints have not been satisfied

JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer

1) I tried few things as mentioned in Maven Java EE Configuration Marker with Java Server Faces 1.2, but no luck. 2)Also I went into .settings and modified org.eclipse.wst.common.project.facet.core.xml and modified jst.web to point to 2.5 or 3.0 version; but I get some other errors.

I am trying to make Sencha GXT examples work in maven/eclipse build based on http://neiliscoding.blogspot.ie/2012/05/how-to-setup-examples-for-use-in-gxt-3.html and having this javaserver faces problem in eclipse. Here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<!-- POM file generated with GWT webAppCreator -->
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>xx</artifactId>
    <groupId>ss</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>guis</artifactId>
<packaging>war</packaging>

<name>GWT Maven Archetype</name>

<properties>
    <!-- Convenience property to set the GWT version -->
    <gwtVersion>2.5.1</gwtVersion>
    <!-- GWT needs at least java 1.5 -->
    <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>com.google.gwt.inject</groupId>
        <artifactId>gin</artifactId>
        <version>2.1.2</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-servlet</artifactId>
        <version>${gwtVersion}</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <version>${gwtVersion}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-dev</artifactId>
        <version>${gwtVersion}</version>
        <scope>provided</scope>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
        <classifier>sources</classifier>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sencha.gxt</groupId>
        <artifactId>gxt-chart</artifactId>
        <version>3.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.sencha.gxt</groupId>
        <artifactId>gxt</artifactId>
        <version>3.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.sencha.gxt</groupId>
        <artifactId>uibinder-bridge</artifactId>
        <version>2.4.0</version>
    </dependency>



</dependencies>

<build>
    <!-- Generate compiled stuff in the folder used for developing mode -->
    <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>

    <plugins>

        <!-- GWT Maven Plugin -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.5.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test</goal>
                        <!-- <goal>i18n</goal> -->
                        <goal>generateAsync</goal>
                    </goals>
                </execution>
            </executions>
            <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
                documentation at codehaus.org -->
            <configuration>
                <runTarget>guis.html</runTarget>
                <hostedWebapp>${webappDirectory}</hostedWebapp>
                <i18nMessagesBundle>com.harmonia.client.Messages</i18nMessagesBundle>
            </configuration>
        </plugin>

        <!-- Copy static web files before executing gwt:run -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <!-- <goals> <goal>exploded</goal> </goals> -->
                </execution>
            </executions>
            <configuration>
                <webappDirectory>${webappDirectory}</webappDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Here is my web.xml file

 <?xml version="1.0" encoding="UTF-8"?>
  <!-- <!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> -->

<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>GXT Created Web Application</display-name>



<!-- Default page to serve -->
<welcome-file-list>
    <welcome-file>guis.html</welcome-file>
</welcome-file-list>

As you can see, I tried different dtds in above web.xml, but I still have the problem. Would appreciate any hints

12

12 Answers

24
votes

Your problem is that you have marked your web.xml as being servlet 2.3 compliant (or perhaps not even that - I am not sure how your doctype in a comment is interpreted)

 <?xml version="1.0" encoding="UTF-8"?>
  <!-- <!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

and you need it to be at least servlet 2.5 compliant for the Eclipse tooling to work.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

(untested - copied from http://javahowto.blogspot.dk/2009/10/sample-webxml-servlet-25.html)

You may need to recreate the Eclipse project to have the changes picked up.

32
votes

I have encountered this with Maven projects too. This is what I had to do to get around the problem:

First update your web.xml as mentioned Thorbjørn Ravn Andersen. I used version 3.0 as below:

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

Then right click on your project and select Properties -> Project Facets In there you will see the version of your Dynamic Web Module. This needs to change from version 2.3 or whatever to version 2.5 or above (I chose 3.0).

However to do this I had to uncheck the tick box for Dynamic Web Module -> Apply, then do a Maven Update on the project. Go back into the Project Facets window and it should already match your web.xml configuration - 3.0 in my case. You should be able to change it if not.

If this does not work for you then try right-clicking on the Dynamic Web Module Facet and select change version (and ensure it is not locked).

Hope that works!

3
votes

I had the same problem and in my web.xml had version 2.5 while the project had the (right-click on Project-> Properties-> Progect 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.

3
votes

The solution that i had found for this problem is

1 ) Right Click on the Project >Properties>Uncheck Dynamic Web Module>Apply And Close.

2 ) Right Click on the Project>Maven>Update Project...

2
votes

My project was facing the same issue. I changed the web.xml as follows:

<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>Archetype Created Web Application</display-name>

The error persisted. But after following the suggestions made in the following link, the issue was resolved.

http://crunchify.com/how-to-fix-cannot-change-version-of-project-facet-dynamic-web-module-to-3-0-error-in-eclipse/

1
votes

My own solution was to put the rignt dependency in the pom.xml.

If the project is declared as a 3.1 Web Dynamic Project in the facets, then the java.servlet-api dependency also has to be the 3.1.0 (or 3.1.x) version.

In my case I had left 3.0.1 version, thus inducing this specific error message in the "Problems" view :

Cannot change version of project facet Dynamic Web Module to 3.0. One or more constraints have not been satisfied.

(of course make sure in addition that your web.xml must also be the 3.1 one).

1
votes

Try this : Delete your project in Eclipse. Delete the Eclipse project, not your application! It should disappear from the list of projects. In Windows Explorer locate your project directory and delete the directories .settings and target (if found) and delete the files .project and .classpath. Back to Eclipse, import existing Maven project. That is all!

Assuming that your web.xml has the right header <web-app> to your target JSF version.

1
votes

I had the same error and I have solved as following:

STEP 1: Update web.xml file, and add the following codes

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

STEP 2 : Write click on the project folder, and select Properties then search "Project Facets" . You need to uncheck "Dynamic Web Module", then Apply and then close it. See Eclipse properties

STEP 3: Update your Maven, then you good to go.

0
votes

**Open your project’s pom.xml and add this plugin tag Finally, right click on your project > Maven > Update Project…

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

**

0
votes

I ran into this problem as well Thorbjørn Ravn Andersen's answer didn't help as I was already at Dynamic Web Module 2.5. I had run into this same issue years before and given up. Deciding to re-investigate what I first did was try and remove support for "Dynamic Web Module" by unchecking it - but hey, it's locked? So I unlocked it and disabled/unchecked it. I then unlocked JavaServer Faces, unchecked it as well, clicked apply - no explosion! With fingers crossed I then re-checked Dynamic Web Module and set it to 3.1. I then re-checked JavaServer Faces setting it to 2.2. Clicked apply - no "big badda boom", it worked - profit! Hope this helps anyone else with the same problem, also it doesn't rely on adjusting XML files.

Note I also did set the java faceted version to 1.8 as well as it was required.

0
votes

For me none of previous worked.

Then I found this link: https://crunchify.com/how-to-fix-cannot-change-version-of-project-facet-dynamic-web-module-to-3-0-error-in-eclipse/

for me was almost the same as described in that link.

  • Go to your Eclipse Workspace location
  • Open file /.settings/org.eclipse.wst.common.project.facet.core.xml.
  • Modify version for jst.web property to 2.5
  • Back in eclipse
  • Right click on Project
  • Refresh
  • Click on Project
  • Select Clean
  • Right-click on project name
  • Click on Maven
  • Update project

Problems gone for me

0
votes

I follow the next steps.

Right click on project -> Properties -> Project Facets. Mark Dynamic Web Module, JavaServer Faces and choose the versions of your project. (If you get the message Cannot change version of project facet Dynamic Web Module follow the next tutorial How to fix Cannot change version of project facet Dynamic Web Module)

Delete the web.xml file, then right click on project -> Java EE Tools -> Generate Deployment Descriptor Stub.

Delete the project from eclipse (don't delete the sources), then at the project root level execute:

mvn eclipse:clean
mvn eclipse:eclipse
mvn clean install -X

Import the project again as Existing Maven Projects.

My web.xml looks like this:

<?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">
    <display-name>jsf-sample</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>