Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cvc-id.3 error in web.xml

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.

like image 953
Arsenicum Avatar asked Jul 10 '10 14:07

Arsenicum


4 Answers

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"

like image 86
user2931195 Avatar answered Nov 18 '22 14:11

user2931195


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.

JSP-related updates

I've ran into pretty much the problem with JSP as well and this time it was enough to change the location of the XSD only, without any namespace or version changes. The latter were applied for web.xml, but this time I only did the following:

<taglib
    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-jsptaglibrary_2_1.xsd"
    version="2.1">

vs.

<taglib
    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://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
    version="2.1">

http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd

vs.

http://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd

The important thing is that I didn't simply invalidated namespaces, but validation still applies. This can easily be tested by adding invalid elements or e.g. add multiple functions with the same names.

cvc-complex-type.2.4.a: Invalid content was found starting with element '{"http://java.sun.com/xml/ns/javaee":foobar}'. One of '{"http://java.sun.com/xml/ns/javaee":description, "http://java.sun.com/xml/ns/javaee":display-name, "http://java.sun.com/xml/ns/javaee":icon, "http://java.sun.com/xml/ns/javaee":tlib-version}' is expected.

WWD in Eclipse contains some catalog file mapping the same actual XSD file under multiple different URI-names. So while in theory the older URI should still be available and used, it doesn't seem to be for some reason. OTOH, the newer URI seems to work for some reason, but in those cases it is necessary to keep the OLD namespaces! Reason simply is that the one and only available file still contains the old namespaces, regardless which URI is used to read it.

Eclipse WWD catalog settings

<uri name="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" uri="file:///C:/Users/tschoening/AppData/Roaming/Eclipse/Java%20Docsrv/configuration/org.eclipse.osgi/1360/0/.cp/dtdsAndSchemas/web-jsptaglibrary_2_1.xsd"/>
<uri name="http://xmlns.jcp.org/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" uri="file:///C:/Users/tschoening/AppData/Roaming/Eclipse/Java%20Docsrv/configuration/org.eclipse.osgi/1360/0/.cp/dtdsAndSchemas/web-jsptaglibrary_2_1.xsd"/>

So, it might be that changing the URI only might have worked with web.xml as well, like it seems to work with my JSP taglibs. Didn't get anything newer to work as well, seems like standards have changed a bit and I would need to adopt more, which I don't want anymore. Legacy-stuff... :-)

like image 30
Thorsten Schöning Avatar answered Nov 18 '22 15:11

Thorsten Schöning


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

like image 7
Jonas Schwindt Avatar answered Nov 18 '22 15:11

Jonas Schwindt


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>
like image 1
ASR Avatar answered Nov 18 '22 16:11

ASR