30

I'm getting this error message while editing web.xml file in eclipse for SpringMVC web-app:

cvc-id.3: A field of identity constraint 'web-app-servlet-name-uniqueness' matched element 'web-app', but this element does not have a simple type.

here is part of my web.xml:

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

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

Error points at the <servlet-name>dispatcher</servlet-name> declaration. What should i do to fix it? Thank you in advance.

BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
Arsenicum
  • 301
  • 1
  • 3
  • 3
  • 3
    The error suggests a problem with the uniqueness of the `servlet-name`. Can we see the whole file, not just that one bit? – skaffman Jul 11 '10 at 21:56

5 Answers5

45

I accidentally found that changing Java to the upper case made the error disappear:

xmlns="http://java.sun.com/xml/ns/javaee"

Should be:

xmlns="http://JAVA.sun.com/xml/ns/javaee"

Anton Krug
  • 1,333
  • 2
  • 16
  • 31
user2931195
  • 563
  • 5
  • 3
  • 9
    Got the same error today. You can actually just put "Java" instead of "java" it works... I chose to add an "s" in https... it solves the errors too. that's some weird stuff... – Michel Apr 14 '21 at 06:35
  • 13
    By using a differetn casing you are technically introducing a different namespace. So, this is not really a solution. – MrTux Apr 29 '21 at 13:46
  • Oh my god, that cannot all be true. How dead is GWT, actually?? – user2618802 Jul 06 '21 at 08:59
  • 1
    I verified that changing it to "JAVA" or "Java" fixes it. Also that switching the url to have "https..." instead of "http..." with no other change seems to do it as well. Simply doing a [Project > Clean] does *not* fix it. – Pete Kelley Jul 28 '21 at 18:36
  • 11
    This is NOT an answer, people are simply hiding the underlying problem by changing the namespace to something not known and ignored by Eclipse. The suggestions have the same effect like using `xmlns="foobar"` https://www.liquid-technologies.com/xml-schema-tutorial/xsd-namespaces – Thorsten Schöning Sep 07 '21 at 14:52
  • Strangely! worked for me too – Shweta Priyadarshani Jan 18 '22 at 13:54
31

Eclipse 2021-06

I've ran into a similar issue with Eclipse 2021-06 today:

cvc-id.3: A field of identity constraint 'web-common-filter-name-uniqueness' matched element 'web-app', but this element does not have a simple type.

Wrong answers

Many of the other suggestions in the answers are simply wrong, because what they are doing is changing namespaces to something not mapped to any schema at all anymore and therefore things won't simply be checked anymore. Some comments make that clear already, so java to Java or http to https or javaee to j2ee at some places really only hides the problem.

The point is that if that message comes, there really is a validation problem which needs to be found and fixed. So while suggestions like cleaning the project, the network cache of Eclipse under Windows/Preferences/Network Connections/Cache etc. are usual Voodoo, they MIGHT(!) work! Though, that wasn't the problem in my case.

Deployment descriptor 3.1

What has worked in my case was changing the deployment descriptor to version 3.1:

<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"
            id="WebApp_ID" version="3.0">

vs.

<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"
            id="WebApp_ID" version="3.1">

Afterwards the validation errors were instantly gone. Though, the important part is that in contrast to introduce invalid/unknown/wrong/... namespaces like in many of the other answers, Eclipse DOES validate! This can easily be tested by really adding the same filter-name twice, which results in the following error:

cvc-identity-constraint.4.1: Duplicate unique value [UrlRewriteFilter] declared for identity constraint "web-common-filter-name-uniqueness" of element "web-app".

That DOES NOT happen with invalid/unknown/wrong/... namespaces, Eclipse wouldn't simply validate at all and the error would be left unrecognized until deployment or even later.

Support for version 3.1 in Tomcat+Eclipse

I need to support legacy apps myself, so checked with which version of Tomcat a corresponding web.xml has been deployed and its 8.0. That should be old enough for a lot of users. Of course Eclipse seems to bundle that version for quite some time as well, otherwise it wouldn't be able to validate right now. Just have a look into the file org.eclipse.jst.standard.schemas_1.2.400.v202101070609.jar.

Changes of 3.0 to 3.1

I've diffed both versions and it seems people mostly changed only namespaces and migrated some types from the associated web-common_*.xsd to web-app_*.xsd itself. Really only minor changes otherwise.

Conclusion

The overall interesting question is why Eclipse stopped working for the former web.xml even though it seems that it was totally correct. Only the namespaces and version number changed, but that worked for years in the past. What I'm not sure about anymore is if older Eclipse validated using language server, like the currently used version does. I wonder if whatever provides the language server might have changed and version 3.0 of the deployment descriptor might simply not be supported at all anymore.

Or something else changed regarding downloading and including the web-common_*.xsd and that's why they needed to refactor types into the parent file.

Of course, neither of this was the issue when the question was actually written in 2010. :-) Though, as the deployment descriptor looks still correct to me, only for some older version, there surely was some other root cause as well than wrong namespaces or alike.

Thorsten Schöning
  • 3,080
  • 21
  • 39
7
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:javaee="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">

Adding a namespace to your xmlns="http://java.sun.com/xml/ns/javaee" Line (eg) xmlns:javaee="http://java.sun.com/xml/ns/javaee" will resolve your problems probably.

There are elements in both definition files, so without a proper namespace they won't be unique

Lova Chittumuri
  • 2,427
  • 1
  • 25
  • 27
Jonas Schwindt
  • 103
  • 1
  • 1
  • 1
    Using `xmlns:javaee` without using `` as well will hide the problem only, pretty much like with all the other answers suggesting `java` to `JAVA` or `http` to `https`. Doesn't it? – Thorsten Schöning Sep 07 '21 at 14:49
0

please find below the tag for web.xml

<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>
ASR
  • 11
  • 4
-4

I've found the following here and here which helps me:

<web-app
  xmlns="http://java.sun.com/xml/ns/j2ee"
  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"
  version="2.5">

The value of attribute xmlns ends with j2ee instead of javaee.

rig
  • 1
  • 2
  • 1
    Don't follow people using `ISO-8859-1` for their XML examples. :-) `j2ee` in combination with a schema location of `javaee` doesn't make much sense. `schemaLocation` maps namespaces to files and `javaee` is nether imported/used. OTOH, `j2ee` is not mentioned in `schemaLocation`, so parsers simply won't validate at all. That's why errors go away. https://stackoverflow.com/a/5875404/2055163 – Thorsten Schöning Sep 07 '21 at 14:57